What is a multi-module Maven project?
IntermediateConceptJava builds (Maven, Gradle, JAR, WAR)
Answer
Short answer
A multi-module project is one parent project containing several child projects (modules) that are built together. The parent pom.xml has <packaging>pom</packaging> and lists the modules; Maven works out the build order from their dependencies (this is called the reactor).
Example layout
shop/
├── pom.xml ← parent: <packaging>pom</packaging>
├── shop-common/pom.xml ← shared code
├── shop-orders/pom.xml ← depends on shop-common
└── shop-payments/pom.xml ← depends on shop-common
<!-- parent pom.xml -->
<packaging>pom</packaging>
<modules>
<module>shop-common</module>
<module>shop-orders</module>
<module>shop-payments</module>
</modules>
Useful commands
mvn clean install # build everything in the right order
mvn -pl shop-orders -am package # build only orders + what it needs (-am = also make)
mvn -T 4 clean package # build modules in parallel with 4 threads
Why DevOps cares
- The parent pom centralises versions (
dependencyManagement) and plugin config for all modules. - In CI,
-pl ... -amlets you build only the changed service — big time savings in monorepos.
What to say in the interview
"A multi-module build has a parent pom with packaging pom listing child modules. The reactor builds them in dependency order. In CI I use -pl and -am to build just the affected module and -T for parallel builds."
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR
More on Java builds (Maven, Gradle, JAR, WAR)
What is pom.xml and what is it used for?BeginnerHow do you build and run a Java project with Maven?BeginnerWhat is the difference between a JAR and a WAR file?BeginnerWhat is Gradle and how is it different from Maven?BeginnerHow do you configure a Spring Boot application for different environments?BeginnerA Maven build fails in the pipeline with "Could not resolve dependencies". How do you fix it?Intermediate