Difference between dependencyManagement and dependencies in Maven

Managing dependencies correctly is one of the most important aspects of working with Apache Maven. A frequent source of confusion for Java developers is understanding the difference between <dependencyManagement> and <dependencies> in a Maven pom.xml.

Although both deal with dependencies, they serve completely different purposes.

In this article, we will see:

  • What <dependencies> does
  • What <dependencyManagement> does
  • The key differences between them
  • How they work together
  • Best practices for real-world Maven projects

What is <dependencyManagement> in Maven?

The <dependencyManagement> section is used to define and control dependency versions without actually adding them to the project. It acts as a central version registry.

So, if you define dependencies under the <dependencyManagement> section and run the command mvn clean install, Maven will not download the dependency and will not add it to the classpath.

Then you might ask, why do we want to add <dependencyManagement>?

It is mainly used in multi-module projects, where in the parent POM, we declare all the dependencies (along with their versions) that are intended to be used by child modules. This ensures:

  • No version conflicts
  • All child modules use the same dependency versions
  • Easy upgrades by changing the version in one place

Example: <dependencyManagement>


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.14.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

What is <dependencies> in Maven?

The <dependencies> section is where you declare the libraries your project actually uses.

Any dependency listed here:

  • Is downloaded by Maven
  • Is added to the project classpath
  • Is available during compile, test, or runtime (based on scope)

Example: <dependencies>


<dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.14.0</version>
    </dependency>
</dependencies>

Key Points About <dependencies>

  • Directly adds dependencies to your project
  • Required for compilation or execution
  • Versions must be specified unless inherited. When versions are defined in <dependencyManagement>, there is no need to specify them again in child POMs.
  • Affects the build immediately

Key Differences Between <dependencyManagement> and <dependencies>

Feature <dependencies> <dependencyManagement>
Adds dependency to project Yes No
Controls version Yes Yes
Required for compilation Yes No
Common in parent POM Optional Very common
Helps avoid version conflicts Limited Yes

How <dependencyManagement> and <dependencies> Work Together

The most common and recommended usage is in multi-module Maven projects.

Parent POM (Version Control)


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.14.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

Child Module (Actual Usage)


<dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>
</dependencies>
  • Version is inherited automatically
  • No need to repeat versions
  • Easy upgrades and consistency

Why <dependencyManagement> Is Important

1. Centralized Version Control

Define dependency versions in one place instead of repeating them across modules.

2. Prevents Dependency Conflicts

Ensures all modules use the same library versions.

3. Simplifies Maintenance

Upgrade a dependency version once instead of everywhere.

4. Enables Clean Child POMs

Child POMs stay simple and readable.


When Should You Use Each?

Use <dependencies> when:

  • Your project actually needs the dependency
  • You want the library on the classpath
  • You are working in a single module or child module

Use <dependencyManagement> when:

  • Managing versions across multiple modules
  • Creating a parent POM
  • Standardizing dependency versions
  • Avoiding transitive dependency conflicts

Common Mistakes Developers Make

  • Expecting <dependencyManagement> to add dependencies automatically
  • Forgetting to declare dependencies in <dependencies>
  • Duplicating versions across modules
  • Mixing incompatible library versions

Best Practices for Maven Dependency Management

  • Always use <dependencyManagement> in parent POMs
  • Declare dependencies without versions in child POMs
  • Prefer BOMs (Bill of Materials) when available
  • Regularly run mvn dependency:tree
  • Keep dependencies updated to avoid security issues

Summary

In simple terms:

  • <dependencies> → What your project uses
  • <dependencyManagement> → How versions are controlled

They are not alternatives — they are complementary.

Understanding this distinction is essential for building clean, scalable, and maintainable Maven projects.

Thanks for reading.