Backend Development 19 min read

Comprehensive Guide to Maven: Configuration, Dependency Management, Modules, Plugins, and Build Settings

This article provides a detailed tutorial on using Maven for Java projects, covering basic configuration, repository setup, dependency management, module organization, plugin usage such as jar, assembly, and shade, as well as build settings and code examples.

Top Architect
Top Architect
Top Architect
Comprehensive Guide to Maven: Configuration, Dependency Management, Modules, Plugins, and Build Settings

This article introduces Maven as a powerful project management and build tool for Java applications, explaining how it simplifies dependency handling, module structuring, and packaging.

1. Basic Configuration

It describes repository configuration (central and private repositories) and the essential elements of a pom.xml file— groupId , artifactId , and version .

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>xyz.ibudai</groupId>
  <artifactId>maven-demo</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <description>This is maven demo.</description>
</project>

2. Dependency Management

The guide explains how to declare dependencies using the <dependencies> tag, set the scope , exclude transitive dependencies, and mark optional ones.

<dependencies>
  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.27</version>
    <scope>runtime</scope>
  </dependency>
</dependencies>

3. Module Configuration

For multi‑module projects, Maven uses the <modules> element and parent POM inheritance via the <parent> tag, allowing child modules to inherit dependency versions and plugin settings.

<modules>
  <module>module-1</module>
  <module>module-2</module>
</modules>

4. Unified Management

To avoid version conflicts across modules, the article shows how to centralize dependency versions in a <dependencyManagement> section of the parent POM.

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.30</version>
    </dependency>
  </dependencies>
</dependencyManagement>

5. Plugin Management

The guide covers three common plugins:

maven-jar-plugin – adds custom entries to the JAR manifest.

maven-assembly-plugin – creates an “uber‑jar” that bundles project classes with all runtime dependencies.

maven-shade-plugin – similar to assembly but supports package relocation and selective inclusion.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.2.0</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals><goal>shade</goal></goals>
    </execution>
  </executions>
  <configuration>
    <minimizeJar>true</minimizeJar>
    <artifactSet>
      <includes>
        <include>com.fasterxml.jackson.core:jackson-core</include>
      </includes>
    </artifactSet>
    <relocations>
      <relocation>
        <pattern>com.fasterxml.jackson.core</pattern>
        <shadedPattern>com.ibudai.fasterxml.jackson.core</shadedPattern>
      </relocation>
    </relocations>
  </configuration>
</plugin>

6. Build Settings

Additional build configurations include setting the Java compiler version, excluding resource files from the final JAR, and specifying the main class for executable JARs.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>8</source>
    <target>8</target>
  </configuration>
</plugin>

<resources>
  <resource>
    <directory>src/main/resources</directory>
    <excludes>
      <exclude>application.yml</exclude>
    </excludes>
  </resource>
</resources>

Overall, the article equips readers with the knowledge to set up Maven projects, manage dependencies efficiently, structure multi‑module builds, and customize packaging through plugins, making it a practical reference for Java backend developers.

Javadependency-managementMavenBuild ToolspluginsModule Configuration
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login 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.