Dependency Management

About

This category includes plugins that help manage how dependencies are resolved, downloaded, analyzed, and maintained within a Maven project. These plugins assist with inspecting the dependency tree, resolving conflicts, managing transitive dependencies, enforcing dependency constraints, and working with repositories.

These tools are especially useful for large or complex projects with many modules or dependencies, where tracking and controlling dependency versions and scopes is critical.

Maven Dependency Plugin

The Maven Dependency Plugin (maven-dependency-plugin) is a key tool for analyzing, resolving, and manipulating project dependencies. It offers a rich set of goals to help us understand the dependencies in our project, copy them, unpack them, or list their structure.

Common Goals

Goal
Description

dependency:tree

Shows the dependency hierarchy (useful for conflict resolution)

dependency:list

Lists all dependencies used in the project

dependency:copy

Copies specific dependencies to a folder

dependency:copy-dependencies

Copies all project dependencies

dependency:unpack

Unpacks dependency JARs into specified directories

dependency:analyze

Analyzes unused or undeclared dependencies

dependency:purge-local-repository

Removes specific artifacts from the local repository to force fresh download

Plugin Configuration

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>3.6.0</version>
</plugin>

// Copying dependencies
<configuration>
  <outputDirectory>${project.build.directory}/libs</outputDirectory>
  <includeScope>runtime</includeScope>
</configuration>

Example

// List dependencies
mvn dependency:list

// Show dependency tree
mvn dependency:tree

// Analyze for unused or undeclared dependencies
mvn dependency:analyze

Versions Maven Plugin

The Versions Maven Plugin (versions-maven-plugin) helps manage versions of dependencies, plugins, and even the parent POM. It is especially useful for identifying outdated dependencies and suggesting updates.

Common Goals

Goal
Description

versions:display-dependency-updates

Lists available newer versions of dependencies

versions:use-latest-versions

Replaces current versions with the latest available

versions:use-next-releases

Updates to the next release version only (no SNAPSHOT)

versions:lock-snapshots

Converts all SNAPSHOT dependencies to specific versions

Plugin Configuration

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>versions-maven-plugin</artifactId>
  <version>2.16.0</version>
  <configuration>
    <allowSnapshots>false</allowSnapshots>
    <generateBackupPoms>false</generateBackupPoms>
  </configuration>
</plugin>

Example

// Display dependency updates
mvn versions:display-dependency-updates

// Use latest versions
mvn versions:use-latest-versions

Maven Install Plugin

The Maven Install Plugin (maven-install-plugin) is responsible for installing our project's artifacts (e.g., JARs, POMs) into the local Maven repository (~/.m2/repository) so they can be reused by other local projects.

This plugin is automatically bound to the install phase of the build lifecycle.

Goal

Goal
Description

install:install

Installs the project artifact into the local repository

Plugin Configuration

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-install-plugin</artifactId>
  <version>3.1.1</version>
</plugin>

Example

mvn install

This will:

  • Compile the code

  • Run tests

  • Package the artifact (JAR/WAR)

  • Install it to your local repository

Maven Deploy Plugin

While more common in release workflows, the Maven Deploy Plugin (maven-deploy-plugin) is closely related to dependency management because it handles publishing artifacts to a remote repository, making them available as dependencies in other projects.

It works with remote repositories like Nexus or Artifactory.

Goal

Goal
Description

deploy:deploy

Uploads project artifacts to a remote repository

Plugin Configuration

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-deploy-plugin</artifactId>
  <version>3.1.1</version>
</plugin>

Example

mvn deploy

We must configure distributionManagement in pom.xml and authentication credentials in settings.xml.

Last updated

Was this helpful?