【问题标题】:Maven compiler Plugin recompiling tests while having maven.test.skip to trueMaven 编译器插件在将 maven.test.skip 设置为 true 时重新编译测试
【发布时间】:2017-03-18 13:52:58
【问题描述】:

当更新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 标志实际上被忽略了。

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

【问题讨论】:

  • 也在MCOMPILER-284 中报告。也许回归是的。
  • @Tunaki 是的,几分钟后我实际上意识到了这一点。我应该首先检查它的 JIRA 而不是 SO,我的错
  • @Tunaki 那我应该删除这个问题吗?
  • IMO 最好保留它,所以对于有相同问题的人来说,SO 可能是第一个去的地方。也可以作为欺骗目标。
  • 好点,Google 在搜索时确实没有帮助我(Maven JIRA 的索引很可能不如 SO)。

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


【解决方案1】:

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

所以这可能是一种回归,有待 Maven 团队进一步确认。


重要提示:将skip 测试传递给testCompile 目标(默认通过默认绑定执行)时会发生相同的行为,如下所示(覆盖其默认ID,@987654327 @):

<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

【讨论】:

  • 我想知道,如果在 POM 中为 testCompile 目标显式配置 &lt;skip&gt; 是否有效?
  • 是的,同样的行为,刚刚测试过。会发布更新
  • 可以确认回归。推送了将包含在 3.6.1 中的修复。
  • @Tunaki 对那些说“Maven 已死”的人我会很快回复“你错了!那里最好的开发人员之一刚刚加入了它的团队,未来是光明的!”。顺便说一句,周一 Robert Scholte 将在 Devoxx Belgium 做关于 Java 9 和 Maven 的演讲,我会在那里并尝试见到他 :) maven 万岁!
  • 太棒了!我也很想去那里:)
猜你喜欢
  • 2013-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-11
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多