Scrivio Interview library
CodingFoundations5 min read · updated 12 November 2026

What is the difference between declaring a dependency under <dependencies> and under <dependencyManagement> in a parent POM? Show what a child module must write to use a managed version.

A dependency under <dependencies> in a parent POM is added to the classpath of every child module. A dependency under <dependencyManagement> adds nothing to any classpath; it only declares the version, scope and exclusions to use whenever that artifact appears, either because a child lists it or because it arrives transitively. So a child that wants a managed library must still list it in its own <dependencies>, usually without a <version>, for example just the groupId com.fasterxml.jackson.core and artifactId jackson-databind.

Why this question is asked

In a multi-module project, the parent POM is where we keep shared configuration, and the two sections look almost the same, which is why they are often confused. Putting a library in the wrong one either forces it on every module or has no visible effect at all. Interviewers ask this to check that we know how Maven separates choosing a version from using a library, the idea that BOMs and platform POMs are built on. In this answer, we will recap parent inheritance, compare the two sections, write what a child module needs, see how managed versions also control transitive dependencies, and explain why inherited dependencies are usually too broad.

1A Quick Recap of Parent POM Inheritance

A child module names its parent in a parent element. Maven then merges the parent's POM into the child's, so the child inherits properties, plugin configuration, repositories and both the dependencies and the dependencyManagement sections. We can see the merged result, the effective POM, with mvn help:effective-pom.

Because both sections are inherited, the difference is not about inheritance. It is about what each section means once inherited: one says use this library, the other says if this library is used, use this version.

2Comparing the Two Sections

Here is a parent POM with one library in each section.

XML
<!-- parent/pom.xml -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.2</version> <!-- only a decision: no classpath effect -->
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version> <!-- added to EVERY child module -->
</dependency>
</dependencies>
The two sections in a parent POM
<dependencies><dependencyManagement>
Adds to classpath?yes, in every childno
Child must list it?no, it is inheritedyes, in its own <dependencies>
Version in childinheritedomitted; taken from the managed entry
Affects transitive deps?noyes: managed version and scope apply
Typical userarely: things truly every module needsversions, scopes, exclusions for all

After this, every child module has slf4j-api on its classpath, whether it logs or not. No child has jackson-databind yet. Jackson only appears in a module that asks for it, and then it gets version 2.18.2. The versions here are examples; in a real project they usually come from a BOM.

3What the Child Module Writes

To use the managed Jackson version, a child declares the dependency in its own dependencies section with groupId and artifactId only. Maven fills in the version, and also the scope and exclusions if the managed entry declares them.

XML
<!-- service/pom.xml -->
<parent>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<!-- no <version>: 2.18.2 comes from dependencyManagement -->
</dependency>
</dependencies>
<!-- mvn dependency:tree -->
<!-- com.example:service:jar:1.0.0 -->
<!-- +- com.fasterxml.jackson.core:jackson-databind:jar:2.18.2:compile -->

If the child writes a version anyway, its own version wins for that module. That is allowed, but it defeats the purpose of central management, so teams usually treat a version in a child as something that needs a reason. If the child omits the version and nothing manages it, the build fails with an error saying dependencies.dependency.version is missing, which is a useful signal that the parent or BOM is incomplete.

4Managed Versions Also Control Transitive Dependencies

dependencyManagement has a second effect that is easy to overlook: it applies to transitive dependencies too. Suppose the child depends on some client library that itself depends on jackson-databind 2.15.0. Without management, Maven's nearest-wins rule might pick 2.15.0. With jackson-databind managed at 2.18.2, Maven uses 2.18.2 wherever Jackson appears in the tree, even though the child never mentioned Jackson.

This is why dependencyManagement is the standard tool for fixing version conflicts and security issues across a whole project. If a vulnerable version of a library arrives through three different paths, one managed entry fixes all of them. mvn dependency:tree -Dverbose shows such cases with a note that the version was managed from another one.

Step throughHow Maven picks the version of a dependency
  1. Is the version written in this module's own dependency?
    Yesuse itNonext check
  2. Is the artifact in the effective dependencyManagement?
    Yesuse the managed version, scope and exclusionsNonext check
  3. Use the nearest version in the dependency treenearest wins; first declared breaks ties

3 steps in order. Play them, or step through them one at a time.

Managed versions apply to both direct and transitive dependencies.

5Why Inherited Dependencies Are Usually Too Broad

Putting libraries in the parent's dependencies section looks convenient: declare once, every module has it. But it means every module, including a small API module or a test utilities module, carries those libraries on its classpath and passes them on to its own consumers. Jars grow, dependency trees get harder to read, and a module cannot opt out, because Maven has no way to remove an inherited dependency.

So the usual rule is: put versions in dependencyManagement, and let each module declare what it really uses. The parent's dependencies section is reserved for the rare library every module needs, and test libraries such as JUnit are a common, acceptable example, since they do not leak through test scope.

6Follow-up questions

Can dependencyManagement set a scope?

Yes. A managed entry can declare a scope, for example test for a testing library, and modules that list the dependency without a scope get it. But a scope in the child's own declaration overrides it, and managed scopes also apply to transitive dependencies, which can surprise people, so many teams manage only versions and exclusions.

How does dependencyManagement relate to a BOM?

A BOM is simply a POM whose main content is a dependencyManagement section. Importing it with type pom and scope import merges that section into ours, so a BOM gives us managed versions without making its POM our parent.

What happens if two parents in a chain manage the same artifact?

The closest one wins: the child's own dependencyManagement, then its parent's, then the grandparent's, because inheritance merges from the top down and lower levels override.

7Conclusion

In this answer, we saw that both sections are inherited by child modules, but they mean different things. Dependencies listed under <dependencies> in a parent are added to every child, which is usually too broad. Entries in <dependencyManagement> only decide the version, scope and exclusions, so a child must still list the dependency in its own <dependencies>, normally without a version. Managed versions also override the versions of matching transitive dependencies, which makes dependencyManagement the main tool for keeping versions consistent.

What to say in the interviewAbout 80 seconds aloud

Open with

Both sections are inherited from a parent, but they mean different things. A dependency under dependencies in the parent is actually added to the classpath of every child module, whether the child needs it or not, and a child cannot remove it, so it is usually too broad. dependencyManagement adds nothing to any classpath.

Then, if they want more

It only declares decisions: which version, and optionally which scope and exclusions, to use whenever that artifact shows up. So a child that wants the library must still list it in its own dependencies, with groupId and artifactId and no version, for example jackson-databind from com.fasterxml.jackson.core, and Maven fills in the managed version.

If the child writes a version, that wins locally, which is why I treat versions in children as needing a reason. The other important effect is that managed versions also apply to transitive dependencies.

If some client library pulls in an old Jackson, the managed version replaces it everywhere in the tree, which is how I fix a conflict or a vulnerable version in one place. mvn dependency:tree with verbose shows where a version was managed.

A BOM is just this idea packaged: a POM with a dependencyManagement section that I import with scope import.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Apache Maven guides
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is the difference between declaring a dependency under <dependencies> and under...": https://scrivio-interview-library.netlify.app/java/maven/4aedc9bc16/