Maven编译器插件重新编译测试,同时将maven.test.skip设置为true

时间:2016-11-04 16:32:15

标签: maven maven-3 pom.xml maven-compiler-plugin

更新pom.xml文件以使用较新的maven-compiler-version3.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标志。

问题:这是回归还是在上面的过程中缺少什么?

1 个答案:

答案 0 :(得分:2)

在尝试将其作为错误报告发布时,我实际上发现它已经报告:

所以这可能是一个回归,需要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