开发者

Publish test utils from maven project

I created a library in maven that can be extended by implementing some interfaces. To test the default implementation I have written some hamcrest matchers that currently live in src/t开发者_JAVA百科est/java.

However, I think they might be useful for users of the library if they want to test their customization.

So how can I make them available? Moving them to src/main would require to make hamcrest a runtime dependency and I don't want that.


There is a way to create a test jar and install it into the repository using the command 'mvn jar:test-jar'. This jar can then be referenced by other projects using the test-jar modifier in the dependency block.

If you want to have this jar built and installed as part of your your normal 'mvn install' build add the following plugin config to your pom:

From http://maven.apache.org/guides/mini/guide-attached-tests.html

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

Then other projects can reference the test jar as follows:

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


As you said, move it to src/main in a new project. Let that project only be used in a test dependency and you don't pollute your module's classpath.


It sounds like you need to move them to their own project and release it. From there you can determine in the original project what scope you'd like.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜