Maven: build only one specific module in a multi-module project
Codemia Knowledge Hub ·
To build one module of a multi-module Maven project, run mvn install -pl module-a from the root. Add -am (--also-make) if the module depends on other modules in the same project, so Maven builds those first.
How a multi-module project is laid out
A multi-module project splits one codebase into smaller Maven projects. Each module can have its own dependencies, build instructions and goals, and inherits shared configuration from a parent project.
The parent POM usually contains no code. It uses pom packaging, declares the common configuration and lists each child module:
Each module's own pom.xml points back to the parent. That link is what applies the inherited configuration to the module:
Building a single module with -pl
When you only work on one or two modules, you do not need to build the whole project. The -pl (--projects) option selects the module to build:
Here module-a identifies the module to compile or install. Maven still honours the dependencies declared in that module's pom.xml.
Building the modules it depends on with -am
If module-a depends on other modules in the project, those must be built too. -am (--also-make) builds the selected module plus every module it depends on. The related option -amd (--also-make-dependents) works in the other direction: it also builds the modules that depend on the selected one.
This builds module-a and any other modules it depends on according to the POM files.
| Option | What it builds |
-pl, --projects | Only the specified module(s). |
-am, --also-make | The specified module(s) plus the modules they depend on. |
-amd, --also-make-dependents | The specified module(s) plus the modules that depend on them. |
Things to keep consistent across modules
- Version management: keep versions consistent when one module depends on another.
- Dependency scoping: scope dependencies properly to avoid classpath pollution.
- Build profiles: use Maven build profiles to adapt the build to different environments.
Related reading
- Maven package/install without test (skip tests)
- Maven parent pom vs modules pom
- Maven plugin for versioning and minifying javascript
- Maven Plugin not found in IntelliJ IDE
- Maven plugins can not be found in IntelliJ
- Maven profiles equivalent of Gradle
- Maven resource filtering not working - because of spring boot dependency
- Maven Resource Filtering with Spring Boot Could not resolve placeholder
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.