How do I include a dependency's test jar into a Maven project's deployment?
Better to configure maven pom file in your first module
<project> <groupId>com.example</groupId> <artifactId>foo</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <build> <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <goals> <goal>test-jar</goal> </goals> </execution> </executions> </plugin>
After this a mvn install/release will also deploy an artifact foo-1.0.0-SNAPSHOT-tests.jar
Then configure the dependency on the test jar with classifier (like suggested in other responses)
<dependency> <groupId>com.example</groupId> <artifactId>foo</artifactId> <version>1.0.0-SNAPSHOT</version> <type>test-jar</type> <!-- uncomment if needed in test scope only <scope>test</scope> --></dependency>
I see you use test-jar
as type
and you used classifier
instead of type
but probably also with test-jar
... but did you try the following?
<dependency> <groupId>com.example</groupId> <artifactId>foo</artifactId> <version>1.0.0-SNAPSHOT</version> <classifier>tests</classifier> <scope>test</scope></dependency>
I'm a bit late to the party, but I hope this helps someone: you can include multiple types of the same dependency. Assume your project depends on common-artifact-1.0.jar
, and there's also a test jar common-artifact-1.0-tests.jar
.
You can import both the jar and the tests jar by doing this:
<dependencies> <dependency> <groupId>my.corp</groupId> <artifactId>common-artifact</artifactId> <version>1.0</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>my.copr</groupId> <artifactId>common-artifact</artifactId> <version>1.0</version> <type>test-jar</type> <scope>test</scope> <!-- the "compile" scope also works here --> </dependency></dependencies>