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 61 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>
![](../../users/profiles/2356554.webp)
Keith
- 2,884
- 2
- 16
- 23
1
Yes, declare a dependency in Module B for Module A following this guide.
![](../../users/profiles/60020.webp)
Samuel
- 15,583
- 5
- 54
- 70
-
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