Maven - test jar

Card Puncher Data Processing

About

A test jar is a jar file used to share test code between module.

Steps

In two steps:

Creation of the test jar

  • Creating the test jar that is shared with the other modules (ie all test class will be package in a test jar)
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<executions>
		<execution>
			<goals>
				<goal>test-jar</goal>
			</goals>
		</execution>
	</executions>
</plugin>

Adding it as a dependency

  • Then in the module that uses this class, add it as dependency
<dependency>
    <groupId>group-id</groupId>
    <artifactId>module1</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <scope>test</scope>
    <type>test-jar</type>
</dependency>

Using

tests

instead of

test-jar

will not work during a reactor build of the test JAR module and any consumer if a lifecycle phase prior to install is invoked. In such a scenario, Maven will not resolve the test JAR from the output of the reactor build but from the local/remote repository.

Documentation / Reference





Discover More
Card Puncher Data Processing
Maven - Test

Test is a phase that: execute the tests. test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed The Maven lifecycle...



Share this page:
Follow us:
Task Runner