如何避免在 Maven 中出现空的测试 JAR?
How do I avoid an empty test JAR in Maven?
我已将 Maven 配置为为所有构建(快照和发布)创建测试 JAR,如下所示:
<plugin>
<!-- generate test-jar artifacts for creating test-test dependencies
across modules -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
这行得通,但有一个我想修复的奇怪行为:Maven 现在尝试为包装 pom
(即父 POM)的模块创建一个测试 JAR。这只是一个小麻烦,但有解决此问题的简单方法吗?
它不会为这些模块创建主 JAR。也许这是 test-jar
目标中的错误?
skipIfEmpty
does the trick, kudos to wemu:
<plugin>
<!-- generate test-jar artifacts for creating test-test dependencies
across modules -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</execution>
</executions>
</plugin>
文档:https://maven.apache.org/plugins/maven-jar-plugin/test-jar-mojo.html#skipIfEmpty
我已将 Maven 配置为为所有构建(快照和发布)创建测试 JAR,如下所示:
<plugin>
<!-- generate test-jar artifacts for creating test-test dependencies
across modules -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
这行得通,但有一个我想修复的奇怪行为:Maven 现在尝试为包装 pom
(即父 POM)的模块创建一个测试 JAR。这只是一个小麻烦,但有解决此问题的简单方法吗?
它不会为这些模块创建主 JAR。也许这是 test-jar
目标中的错误?
skipIfEmpty
does the trick, kudos to wemu:
<plugin>
<!-- generate test-jar artifacts for creating test-test dependencies
across modules -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</execution>
</executions>
</plugin>
文档:https://maven.apache.org/plugins/maven-jar-plugin/test-jar-mojo.html#skipIfEmpty