Java › Build Tools: Maven & Gradle

How would you configure a multi-module Maven or Gradle project, and what benefits does modularizing a large codebase this way provide?

Advanced

Answer

A multi-module project has a parent pom.xml (Maven) or settings.gradle (Gradle) declaring child modules, each with its own build file but sharing common configuration/dependency versions from the parent -- this lets a large codebase be split into independently buildable, testable units (like separate api, core, and web modules) with explicit inter-module dependencies, enabling faster incremental builds (only rebuilding changed modules and their dependents), clearer architectural boundaries, and the ability to publish/version modules independently if needed.
<!-- parent pom.xml -->
<packaging>pom</packaging>
<modules>
    <module>core</module>
    <module>api</module>
    <module>web</module>
</modules>

<!-- web/pom.xml declares a dependency on the sibling module -->
<dependency>
    <groupId>com.example</groupId>
    <artifactId>core</artifactId>
    <version>${project.version}</version>
</dependency>
Real-world example A large enterprise application splits into core (shared domain logic), api (REST controllers), and batch (scheduled jobs) modules within one multi-module Maven build, letting the team run and test just the core module in isolation during development while still building the entire application together for deployment.

Common follow-ups: How does Gradle's project isolation and configuration-on-demand feature improve multi-module build performance further?;What are the trade-offs of a multi-module monorepo versus splitting into entirely separate repositories?