Generating a JAR of the test classes
There could be situations when you would want to use the test classes and resources of a project as a test dependency in another project. This is typically the case in multi-module projects, where a module depends on another module. There could be utility code in the test classes of a module that can be reused in another module.
One way to achieve this would be by creating a separate project to hold these classes. However, that is cumbersome and may be confusing as well.
Maven provides another way to achieve this.
How to do it...
- Open a project for which you want to create a test JAR (
project-with-test-jar
). - Add the following plugin configuration to the
pom
file:<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.5</version> <executions> <execution> <goals...