更新pom.xml
文件以使用较新的maven-compiler-version
,3.6.0
并传递-D=maven.test.skip=true
选项时,实际上不会跳过测试编译。
基于以下示例POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>sample-compiler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</project>
将maven-compiler-plugin
版本设置为上一个3.5.1
时,在调用时会有效地跳过测试编译:
mvn clean test -Dmaven.test.skip=true
会产生:
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ sample-compiler ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ sample-compiler ---
[INFO] Tests are skipped.
但是,当将其升级到3.6.0
并调用上述相同的命令时,我们会:
[INFO] --- maven-compiler-plugin:3.6.0:testCompile (default-testCompile) @ sample-compiler ---
[INFO] Not compiling test sources
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\data\eclipse-workspace\sample-compiler\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ sample-compiler ---
[INFO] Tests are skipped.
注意额外的Changes detected - recompiling the module!
意味着实际忽略了maven.test.skip
标志。
问题:这是回归还是在上面的过程中缺少什么?
答案 0 :(得分:2)
在尝试将其作为错误报告发布时,我实际上发现它已经报告:
MCOMPILER-284
:maven.test.skip
没有跳过测试编译所以这可能是一个回归,需要Maven团队进一步确认。
需要注意的重要事项:将skip
测试传递给testCompile
目标(默认情况下通过默认绑定执行)时会发生相同的行为,如下所示(覆盖其默认值) id,default-testCompile
):
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>default-testCompile</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
解决方案:解决此问题
3.5.1
或3.6.1
,现在为available