Last updated: 2022-08-23

  1. Learn
  2. Multi-Module
  3. Test Jars Maven

Creating Test Jars in Maven for multi-module projects

In multi-module projects, individual modules often contain classes or resources that should also be used in modules based on them - e.g. for initializing test users. In Maven, the maven-jar-plugin can be used to create a referenceable test library for this purpose.

Suppose we have a simple Spring Boot application with two modules "base" and "web". An integration test in "web" now needs to access a method initTestUsers, which is stored inside the "src/test/java" section in "base".

First, the pom.xml of the module "base" must be extended to provide a jar of the test classes.

Adding maven-jar-plugin to the module providing the test data

Now the new library can be referenced from "web". The scope "test" makes it available for testing only, so it will not be included in the final "fat jar" of our Spring Boot executable.

Referencing the new test jar

Using Bootify, prototypes for Spring Boot applications can be created within minutes - develop a concept within the team first and then directly focus on the business logic. In the Professional Plan, the multi-module option is available, which automatically sets up the maven-jar-plugin for Maven projects.

Learn more
or see pricing