问题描述
如何告诉Intellij IDEA不要在工件中包含测试类?我正在做很多项目,所以如果有一个解决方案,比如忽略 project-dir / test
目录中的所有内容,或者甚至更好放入jar中只有来自 project-dir / src
的类。
你好吗?在IntelliJ IDEA中配置jar文件?
如果我转到项目结构(cmd +;在Mac上,在Windows上按ctrl + shift + s)并选择Artifacts,当我使用From modules with dependencies添加一个新工件时,我可以选择是否包含测试:
这里我选择模块输出,这应该只添加模块中的类文件,而不是测试文件(假设你有测试目录标记为测试目录,而不是源目录)。
如果查看该截图的左侧,在项目结构窗口后面,您可以看到我在src / main / java中有生产代码,在src / test / java中有测试代码,这个测试代码是绿色的 - 如果我这样配置的话,这不会出现在我的jar文件中。
How to tell Intellij IDEA not to include test classes in artifact? I'm working on a lot of projects so it's better if there's a solution like "ignore everything in project-dir/test
directory", or even better "put in the jar only classes from project-dir/src
.
How are you configuring the jar file in IntelliJ IDEA?
If I go to Project Structure (cmd + ; on Mac, ctrl + shift + s on Windows) and select "Artifacts", when I add a new artifact using "From modules with dependencies" it gives me the option of including tests or not:
If I add a new jar file using "Empty", then I can choose exactly what appears in the jar file:
Here I select "Module Output" and this should only add the class files from your module, not the test files (assuming you have your test directory marked as a test directory, and not as a source directory).
If you look to the left of that screenshot, behind the project structure window, you can see that I have production code in src/main/java and test code in src/test/java, and this test code is coloured green - this does not appear in my jar file if I configure it this way.
这篇关于Intellij IDEA将junit测试放入jar中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!