Last updated: 2025-05-30

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

Creating Test Jars in Maven for multi-module projects

In multi-module projects, the test part of your modules often contain classes or resources that should also be available for 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. A multi-module option is available in the Professional plan, allowing you to create a custom module structure and assign your entities and security configs accordingly. The maven-jar-plugin is automatically set up for Maven projects.

Learn more
or see pricing