Book Image

Apache Maven Cookbook

Book Image

Apache Maven Cookbook

Overview of this book

Table of Contents (18 chapters)
Apache Maven Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...

  1. Open a project for which you want to create a test JAR (project-with-test-jar).

  2. 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...