【问题标题】:Maven 2.2.1 attached tests. Issue -Dmaven.test.skip=trueMaven 2.2.1 附加测试。问题 -Dmaven.test.skip=true
【发布时间】:2013-07-03 17:26:24
【问题描述】:

我正在使用插件在另一个模块的测试中附加测试。

  <build>
    <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-jar-plugin</artifactId>
       <version>2.2</version>
       <executions>
         <execution>
           <goals>
             <goal>test-jar</goal>
           </goals>
         </execution>
       </executions>
     </plugin>
    </plugins>
  </build>

并且在需​​要jar的模块中:

   <dependency>
      <groupId>com.myco.app</groupId>
      <artifactId>foo</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
  </dependencies>

它对我很有用,但是我发现了一个问题:当我执行“clean install -Dmaven.test.skip=true”时,也需要依赖test-jar,进程失败

【问题讨论】:

  • 你能告诉我们错误吗?

标签: java unit-testing maven maven-2


【解决方案1】:

是的,因为 -Dmaven.test.skip=true 只是让 maven junit 插件(surefire 和 failsafe)不执行 - 它阻止它们运行任何测试。

它确实 NOT 阻止 maven 尝试“收集”所有测试范围的依赖项。 maven 仍然收集所有这些。

如果您想要可选的依赖项(无论范围如何),您应该阅读maven profiles - 您可以定义一个配置文件,其中将定义此依赖项,然后只有在您激活配置文件时,maven 才会尝试获取它(来自例如命令行)

【讨论】:

  • 那么,maven 站点的评论是怎么回事? “如果你绝对必须,你也可以使用 maven.test.skip 属性来跳过编译测试。maven.test.skip 受到 Surefire 的尊重......”有了这个评论,我认为编译会被避免,maven.apache.org/surefire/maven-surefire-plugin/examples/…
  • ...它仍然会尝试获取依赖项。它只是不会对他们做任何事情。
  • 我发现报告的问题可以解决这个问题jira.codehaus.org/browse/MNG-4192
  • @JaviPedrera - 自 2009 年以来一直开放。我不会等待 :-)
  • 哈哈,我知道了,我不会等的,我会尝试解决方法,谢谢
【解决方案2】:

-Dmaven.skip.test-DskipTests 只是跳过测试执行,它仍然编译测试类,所以它需要测试依赖项

如果你想跳过测试类的编译,你可以配置maven编译器插件来这样做,更有用的是创建单独的构建配置文件并通过指定特殊的构建配置文件按需跳过编译

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <executions>
                <execution>
                    <id>default-testCompile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 2011-06-12
    • 1970-01-01
    • 2021-10-04
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    相关资源
    最近更新 更多