How can I refer to maven dependency unit test classes in my java project?

I need to reference some JUnit tests (src / test / java) from project B in the test package src / test / java of project A, while B is maven dependent on A.

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

+5
source share
1 answer

Your pom in project B should enable 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" in test-jar allows you to access test classes from this dependency.

+9
source

All Articles