2013-07-03 53 views
1

我正在使用该插件在另一个模块的测试中附加测试。Maven 2.2.1附加测试。问题-Dmaven.test.skip = true

<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> 

它一直对我非常有用,但我发现了一个问题:当我执行“干净安装-Dmaven.test.skip = true“,还有需要依赖性测试jar,并且该进程失败

+0

您能告诉我们错误吗? –

回答

5

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

它的确如此不是阻止maven试图“收集”所有的测试范围的依赖关系。 maven仍然收集所有这些。

如果你想要可选的依赖关系(不管范围如何),你应该阅读关于maven profiles - 你可以定义一个配置文件来定义这个依赖关系,然后maven只有在激活配置文件时才会尝试获取它命令行,例如)

+0

那么,maven网站上的评论是什么? “如果你绝对必须的话,你也可以使用maven.test.skip属性来跳过编译测试,maven.test.skip受到Surefire的支持......”这个评论我认为可以避免编译,http:///maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-test.html –

+0

...它仍然会尝试获取依赖关系。它只是不会对他们做任何事情。 – radai

+0

我发现了报告的问题来解决这个http://jira.codehaus.org/browse/MNG-4192 –

2

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

如果你想跳过测试类的编辑,你可以配置Maven编译器插件要做到这一点,更有帮助的是创建单独的构建配置文件并按需要跳过sp编译ecifying特殊版本配置文件

<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>