8

I need to reference some JUnit Tests (src/test/java) from project B in the test package src/test/java of project A whereas B is a maven dependecy of 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 controll.

Thanks for your advice

1

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

1 Comment

for what it's worth, it seems that <type>test-jar</type> in the dependecy only imports the test classes. so if you want the regular sources, which might be the case, you have to define the same dependency with <type>jar</type>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.