Master Maven Multi‑Module Design: Inheritance, Aggregation, and Private Repositories

This guide explains how to split a large Java project into Maven modules, use parent‑project inheritance and aggregation to share configurations, manage dependency versions with dependencyManagement, and configure a private repository for releasing SNAPSHOT and RELEASE artifacts, complete with practical code snippets and step‑by‑step instructions.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Master Maven Multi‑Module Design: Inheritance, Aggregation, and Private Repositories

Modular Design and Development

Breaking a large project into smaller Maven modules simplifies management, maintenance, and extension while enabling resource sharing and inter‑module references.

Design strategies include:

Split by functional modules such as common components, product module, shopping‑cart module, etc.

Split by layer: common components, entity classes, controller layer, business layer, etc.

Combine functional modules with layers for finer granularity.

Inheritance and Aggregation

Inheritance

Inheritance in Maven mirrors Java inheritance: a child module can inherit configuration from a parent module, supporting single inheritance only. It simplifies dependency configuration and provides unified dependency management.

Implementation steps:

Create a Maven module (e.g., Xxx-parent) with packaging set to pom.

In the child module’s pom.xml, declare the parent relationship using the <parent> element.

Define common dependencies in the parent’s pom.xml so that children inherit them automatically.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <!-- Parent inherits Spring Boot’s parent -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.wyyzs</groupId>
    <artifactId>tilas-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <!-- Common dependencies -->
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.38</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>3.4.6</version>
        </dependency>
    </dependencies>
    <!-- Version management -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.aliyun.oss</groupId>
                <artifactId>aliyun-sdk-oss</artifactId>
                <version>${aliyun.sdk.version}</version>
            </dependency>
            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>${jaxb.api.version}</version>
            </dependency>
            <dependency>
                <groupId>io.jsonwebtoken</groupId>
                <artifactId>jjwt</artifactId>
                <version>${jjwt.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

Key notes:

When a child inherits a parent, the groupId can be omitted because it is taken from the parent.

The relativePath points to the parent POM; if omitted Maven searches the local or remote repository.

If the same dependency is declared with different versions in parent and child, the child’s version wins.

Aggregation

Aggregation groups multiple modules under a single “empty” parent project (packaging pom) to build the whole system in one step.

Purpose: Quickly build the entire project without manually ordering modules.

Implementation: Use the <modules> element in the parent POM to list child module names.

The build order is automatically resolved based on inter‑module dependencies, independent of the order in the <modules> list.

Private Repository (Nexus/Artifactory)

Introduction

A private repository is a LAN‑hosted Maven repository that proxies external central repositories, enabling internal resource sharing and synchronization.

Dependency lookup order:

local repository → private repository → central repository

.

Release vs. Snapshot

RELEASE versions are stable, no longer updated, and stored in the private repository’s RELEASE area.

SNAPSHOT versions are development builds, stored in the SNAPSHOT area.

Upload and Download Steps

Configure the private repository credentials in settings.xml under the <servers> section.

Define the repository URL for downloading in settings.xml using <mirrors> and <profiles>.

By default only SNAPSHOTs are allowed; to enable RELEASEs add a profile that permits them.

In the project’s pom.xml (or via IDE) set the distributionManagement URLs for deployment.

backendJavadependency managementmavenMulti‑moduleInheritanceaggregationPrivate Repository
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

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.