Creating a Multi-Module Maven Project
Fast recall
Quick revision
Core answer
pom that lists submodules in . Each submodule is a subdirectory with its own pom.xml that declares the root as its . Running mvn install at the root builds all modules in dependency order.Whether you can structure a large Java application into cohesive, independently-buildable modules.
Not specifying `<relativePath>` in the child's `<parent>` block, causing Maven to look in the local repository for the parent POM instead of the local file system during development.
Mention using `<dependencyManagement>` in the parent to centralize versions, building individual modules with `mvn install -pl :module-name -am` (`-am` builds dependency modules first), and the Maven Reactor for build ordering.
Interview-ready guide
Interview answer
A multi-module Maven project uses a root POM to orchestrate the build and share configuration across related modules. The key is understanding what the root POM does and what each child declares itself.
Root POM structure
- The root POM uses
and serves two separate roles: thepom block lists child directories for Reactor build orchestration, anddefines shared dependency versions that children inherit in the child'sblock points to the parent POM location on the filesystem — without it, Maven looks in~/.m2/repositoryfirst, which fails on fresh checkouts before the parent has been installed locally- Inter-module dependencies use
${project.version}to stay synchronized — hardcoding a version in a module reference means you must update it manually every release
Maven Reactor — build ordering
- The Reactor analyzes
references between modules to determine build order automatically —servicedepending oncoremeanscorealways compiles first mvn install -pl :service -ambuilds the target module and all its upstream dependencies, skipping unrelated modules — the most useful productivity command in large multi-module projectsmvn install -pl :service,core -amdbuilds a module and everything that depends on it downstream — useful for validating a change ripples correctly through consumers
Shared configuration best practices
- Define all dependency versions in
at the root — children declare what they need, the root controls which version; no version drift between modules - Define plugin configuration in
at the root and bind plugins in child POMs — this separates "what version of the plugin" from "which modules use it" - Never commit Nexus credentials to the root POM — keep the
URL in the POM and credentials in~/.m2/settings.xmlor CI environment variables
Creating a Multi-Module Maven Project
Direct Answer
A multi-module Maven project has a root POM with <packaging>pom</packaging> that lists submodules in <modules>. Each submodule is a subdirectory with its own pom.xml that declares the root as its <parent>. Running mvn install at the root builds all modules in dependency order.
Common Mistakes & Pitfalls
Not specifying <relativePath> in the child's <parent> block, causing Maven to look in the local repository for the parent POM instead of the local file system during development.
Check your understanding
Answer these without looking back at the article.
- How do you release all modules of a multi-module project at the same version?
- What is the Maven Reactor and how does it determine build order?
- How do you skip a specific module in a multi-module Maven build?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.