Maven is a powerful project management tool that is based on POM (project object model). It is used for projects to build, manage dependency and documentation.
Maven addresses two aspects of building software: first, it describes how software is built, and second, it describes its dependencies.
so coming to
dependencymanagement vs dependencies tag in maven
maven has two mechanisms to add the dependencies of other modules/project. One is Dependencies tag and other is Dependency Management. People often wonder what the difference between the two. An important question is when to use what?
|
First, of all, we should have an idea of what is multi module applications.
As in the case in case of multi module applications only they differ.
A multi-module project is, as its name suggests, a project that consists
of multiple modules, where a module is a project. You can think of a
multi-module project as a logical grouping of sub-projects.
The packaging of a multi-module project is “pom” since it consists of a pom.xml
file but no artifact (jar, war, ear, etc).

That’s a technical story. But it is not great if we are trying to teach some one. As concepts should be as simple
as a story for a freshers. So let’s understand dependencies and dependency management.
There is a man called Manoj, he has two ice cream parlors, Amul, and Baskin Robbins.
Manoj has two children Atharva and Aahna.
Manoj has 2 ice cream in Amul ice cream parlor – mango[ basic version ] and straberry[ moderate version]
and 1 ice cream in Baskin Robbins – black current[high version].
Both Atharva and Aahna can have all the ice creams which their father has in Amul parlor, but they can
have ice cream from Baskin Robbins only if they ask for it.Which means they can only have black ice
cream oly if they specificaly ask for it, but they don’t have to mention which version of black ice creamthey
need, as their father Manoj already know which kind of black current ice we have.
Here Manojis parent module and, Atharva and Aahna are child modules.Amul is dependencies tag and
Baskin Robin is Dependency Management tag.
So all the dependencies present in dependencies tag will be available to all its child modules.But all the
dependencies present in dependency management of parent module will be available to the child only
if those dependencies are declared in dependencies tag of child module.
So why are we even using dependency management if dependencies tag passes all the dependency to
its children?
- As all the children might not need all the dependencies present in parent module,
so it is always wise to use Dependency Managment.
- Using Dependency Managment we can create a consistency of which version and tag of any artifact which
we are using through out the application.[It help to maintain the version of artifact]
- Dependency Managment manage version, scope, and exclusion of artifact in child modules.
Example –
parent-pom.xml
1
2
3
4
5
6
7
8
9
|
< dependencyManagement >
< dependencies >
< dependency >
< groupId >junit</ groupId >
< artifactId >junit</ artifactId >
< version >3.8</ version >
</ dependency >
</ dependencies >
</ dependencyManagement >
|
child-pom.xml
1
2
3
4
5
6
|
< dependencies >
< dependency >
< groupId >junit</ groupId >
< artifactId >junit</ artifactId >
</ dependency >
</ dependencies >
|
|
Comments