How do I reference Maven dependent unit test classes in my java project?

I need to reference some JUnit tests (SRC / test / Java) in project B in the test package Src / test / Java of project a, and B is a maven dependency of project a

Is this even possible?

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

Both projects are under my control

Thank you for your advice

Solution

Your POM in project B needs to include this plug-in:

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

You can then access it from project a as follows:

<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 the test class from this dependency

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>