I have maven project with module A and module B which depends on module A. For example I have abstract unit test in module A and I want to use this unit test in unit tests for module B. Is there any way to achieve that?
Asked
Active
Viewed 76 times
2 Answers
2
You'll want to use the <goal>test-jar</goal>
execution of the maven-jar-plugin
to make the Jar file, then simpy include it as a dependency in your other project, by adding <type>
and <scope>
attributes in the definition of that dependency:
<dependency>
...
<type>test-jar</type>
<scope>test</scope>
</dependency>

Keith
- 3,079
- 2
- 17
- 26
1
Yes, declare a dependency in Module B for Module A following this guide.

Samuel
- 16,923
- 6
- 62
- 75
-
I am not sure that src/test/java is packaged as part of Maven-distributed jars. – Aug 10 '15 at 20:48
-
1The test-jar goal of the maven-jar-plugin will package the test-classes into a jar. https://maven.apache.org/plugins/maven-jar-plugin/test-jar-mojo.html – Samuel Aug 10 '15 at 20:54