如何在 jar 文件中排除 Test.java 类
How to exclude Test.java classes in jar file
我开发了一些实用程序 classes,包括
FileHelper.java
Helper.java
和相应的测试classes
FileHelperTest.java
HelperTest.java
我可以毫无问题地编译、安装和部署项目。
到目前为止一切顺利。当我将此 jar 文件包含在另一个项目的 pom 文件中以使用我的实用程序时出现问题 classes
而测试class也出现在intelliscence中,这当然不是很好的做法
我已经尝试了几乎所有可用的解决方案来将测试 classes 排除到 jar 文件中,但所有解决方案都有助于在构建过程中跳过单元测试执行而不阻止测试 classes成为 jar 文件的一部分。
我尝试了不同的插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<excludes>
<exclude>**/FileHelperTest.java*</exclude>
<exclude>**/HelperTest.java*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/FileHelperTest*</exclude>
<exclude>**/HelperTest*</exclude>
</excludes>
</configuration>
</plugin>
还有一些 .m2 文件总是包含。
希望我已经详细解释了我的问题,希望您已经偶然发现了这个问题并成功解决了它,在此先感谢。
如果你的项目是maven项目那么一般我们将test类保留在“src/test/java”包结构中,maven不会将test类打包在jar中。
所以如果没有明确说明,maven不会将编译好的测试类打包到打包的jar中
If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.
mvn install -Dmaven.test.skip=true
根据 document
我开发了一些实用程序 classes,包括
FileHelper.java
Helper.java
和相应的测试classes
FileHelperTest.java
HelperTest.java
我可以毫无问题地编译、安装和部署项目。
到目前为止一切顺利。当我将此 jar 文件包含在另一个项目的 pom 文件中以使用我的实用程序时出现问题 classes
而测试class也出现在intelliscence中,这当然不是很好的做法
我已经尝试了几乎所有可用的解决方案来将测试 classes 排除到 jar 文件中,但所有解决方案都有助于在构建过程中跳过单元测试执行而不阻止测试 classes成为 jar 文件的一部分。
我尝试了不同的插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<excludes>
<exclude>**/FileHelperTest.java*</exclude>
<exclude>**/HelperTest.java*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/FileHelperTest*</exclude>
<exclude>**/HelperTest*</exclude>
</excludes>
</configuration>
</plugin>
还有一些 .m2 文件总是包含。
希望我已经详细解释了我的问题,希望您已经偶然发现了这个问题并成功解决了它,在此先感谢。
如果你的项目是maven项目那么一般我们将test类保留在“src/test/java”包结构中,maven不会将test类打包在jar中。 所以如果没有明确说明,maven不会将编译好的测试类打包到打包的jar中
If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.
mvn install -Dmaven.test.skip=true
根据 document