Sharing Test code in Maven

Your pom in project B needs to include this plugin:

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

Then, you can access it from project A like this:

<dependency>
    <groupId>XYZ</groupId>
    <artifactId>B</artifactId>
    <version>${project.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

Changing ‘type’ to test-jar allows you to access test classes from that dependency.

发表评论

电子邮件地址不会被公开。 必填项已用*标注