首页 » 文章 » maven 模块间共享test类,test 类依赖 dependency---使用classfier

maven 中如果一个module以来另一个模块的test class,需要使用maven-jar-plugin和classifier(最新的用type代替了)

1.项目a(被b以来的test class)

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

2.项目b,以来a中的test calss

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

添加新评论