Backend Development 8 min read

Using Maven Reactor for Selective Multi‑Module Builds

This article explains how Maven’s reactor determines build order in a parent‑child multi‑module project and demonstrates how to use command‑line options such as -pl, -rf, -am, and -amd to build only required modules or their dependents, greatly speeding up the build process.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Using Maven Reactor for Selective Multi‑Module Builds

The example Maven project uses a parent‑child (aggregator) structure where the top‑level b2b module contains two sub‑modules b2b_account and b2b_order , each of which further contains jar‑type sub‑modules.

Reactor

Running mvn clean install in the b2b/pom.xml directory triggers Maven’s reactor, which analyses inter‑module dependencies and computes a build order for all seven artifacts (including the parent pom). The reactor ensures that modules like b2b-account-api , which are depended on by others, are built first.

Selective Build

When only certain modules need to be rebuilt, Maven provides several options:

-pl <arg>

Alias for --projects <arg> ; specifies a comma‑separated list of modules to build. Modules can be referenced by relative path or by groupId:artifactId .

mvn clean install -pl b2b-account
mvn clean install -pl b2b-account/b2b-account-api
mvn clean install -pl b2b-account/b2b-account-api,b2b-account/b2b-account-service
mvn clean install -pl :b2b-account-api,b2b-order/b2b-order-api
mvn clean install -pl :b2b-account-api,:b2b-order-service

-rf <arg>

Alias for --resume-from <arg> ; starts the reactor from the specified module, skipping earlier modules.

mvn clean install
mvn clean install -rf b2b-order/b2b-order-service

-amd

Alias for --also-make-dependents ; builds the specified modules and any modules that depend on them.

mvn clean install -pl b2b-account/b2b-account-api -amd

-am

Alias for --also-make ; builds the specified modules together with all of their dependencies.

mvn clean install -pl b2b-order/b2b-order-service -am

Using these options, developers can efficiently rebuild only the parts of a large e‑commerce project that are affected by changes, avoiding the time‑consuming full build of every module.

backendJavaMavencommand linebuildReactorMulti-Module
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.