Maven 2.2.1附加测试.问题-Dmaven.test.skip = true

Jav*_*era 1 java maven-2 unit-testing maven

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

  <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>
Run Code Online (Sandbox Code Playgroud)

在需要jar的模块中:

   <dependency>
      <groupId>com.myco.app</groupId>
      <artifactId>foo</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
  </dependencies>
Run Code Online (Sandbox Code Playgroud)

它对我来说非常有用,但是我发现了一个问题:当我执行"clean install -Dmaven.test.skip = true"时,还需要依赖test-jar并且进程失败

rad*_*dai 5

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

阻止行家从试图"收集"所有的测试范围dependenies的.maven仍然收集所有这些.

如果你想要读取有关maven配置文件的可选依赖项(无论范围是什么)- 你可以定义一个配置了这个依赖关系的配置文件,然后maven只有在你激活配置文件时才会尝试获取它(从命令行,例如)