Backend Development 19 min read

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

This article provides a detailed tutorial on Maven, covering basic configuration, repository setup, dependency management, module organization, plugin usage (including jar, assembly, shade), and build settings, with examples and code snippets to help Java developers efficiently manage projects.

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

For developers who have experienced the pain of manually handling JAR files and compatibility issues, Maven offers a powerful solution for project management, dependency handling, and build automation.

1. Basic Configuration

Define the project structure in <project>... with groupId , artifactId , and version . Configure repositories so that Maven first checks a private repository before falling back to the central one.

2. Dependency Management

Use the <dependencies> section to declare required libraries, e.g.:

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

Control transitive dependencies with <excludes> and optional dependencies with <optional>true</optional> . Centralize versions using <dependencyManagement> in a parent POM.

3. Module Configuration

Multi‑module projects are defined with the <modules> tag. Child modules inherit the parent’s dependency management and can add their own dependencies.

4. Plugin Management

Common plugins include:

maven-jar-plugin – adds custom entries to MANIFEST.MF .

maven-assembly-plugin – creates an "uber JAR" that bundles all dependencies.

maven-shade-plugin – similar to assembly but allows fine‑grained inclusion, package relocation, and file filtering.

Example of the shade plugin configuration:

<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>
    <filters>
      <filter>
        <artifact>*:*</artifact>
        <excludes>
          <exclude>META-INF/license/**</exclude>
          <exclude>META-INF/*</exclude>
        </excludes>
      </filter>
    </filters>
  </configuration>
</plugin>

5. Build Settings

Specify the Java version with the maven-compiler-plugin , exclude resources from the final JAR, and set the main class via the spring-boot-maven-plugin or maven-jar-plugin configuration.

Overall, the guide walks through setting up Maven repositories, managing dependencies, structuring multi‑module projects, and leveraging plugins to produce customized, reproducible builds for Java applications.

Javabackend developmentdependency managementMavenBuild Tools
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.