1

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?

Korobko Alex
  • 786
  • 1
  • 6
  • 9

2 Answers2

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
  • 2,884
  • 2
  • 16
  • 23
1

Yes, declare a dependency in Module B for Module A following this guide.

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
  • 1
    The 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