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 to your local repository and will not add it to the classpath of your project.

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 or dependencies 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.

How to Use Lombok to remove boilerplate setters getters in Java

Hello Friends,

One of the points which is said time and again against Java is that ,we have to write a lot of boilerplate
code in the form of setters and getters for our simple POJO classes which unnecessarily increases the
length of our code.

To tackle this problem, there is an open source project called Project Lombok which solves this problem
by allowing you to just write few annotations and it will generate getters and setters in the .class which
are generated from Java files.


How to SetUp Eclipse on Mac machine to run Java Programs

Dear Friends,

In this tutorial we will see how to setup Eclipse on Mac machine to run Java programs.So here are the steps :

How to Install Java/JDK on your windows machine

Dear Friends,

Let  us see how we can install Java on a windows machine.I am taking here an example of 32 bit Windows 7 machine and the version of Java that we are going to install here is 1.6

Step 1 : Go to Oracle site .I am pasting here the direct link from where Java6 exe can be downloaded.

http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR

History of Java language

Dear  Friends,

Let us see evaluation of one of the most used programming language today i.e Java.

  • Java language project was started in June 1991 by team of engineers in Sun microsystem including James Gosling, Mike Sheridan, and Patrick Naughton known by Green Team and lead by James Gosling.

How Java is Platform Independent

Anyone who starts learning Java will agree that the first thing they will hear is that Java is Platform Independent language.

SO WHAT DOES THAT MEAN BY PLATFORM INDEPENDENT.

For this to understand ,first we need to understand what do we mean by platform.

Platform = Hardware + Operating System