Maven tag <dependencyManagement> does not create dependencies, but informs of which dependency versions will be used in the project. Usually <dependencyManagement> is defined either in parent pom.xml in multi-module project or in parent project. If the version is set explicitly in <dependency> tag, then Maven uses defined version, otherwise maven tries to find version in <dependencyManagement>. In Maven there is so called bom (bill of materials) – list of artefacts exported by the project. It is helpful for handling dependencies versions and eliminating dependencies versions conflicts. In other words, bom is special pom which is used for handling dependencies versions and provides an opportunity for centralized defining and updating this versions. Bom usually contains <dependencyManagement>.
There are two common ways of using bom :
- Projects inherit from one parent
<parent>
<groupId>bomGroupId</group>
<artifactId>bomArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
- In big projects first way is not always convenient since projects can inherit only from one parent. More flexible alternative is importing bom
<dependencyManagement>
<dependencies>
<dependency>
<groupId>bomGroupId</groupId>
<artifactId>bomArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
More detailed about Maven dependency scopes – here
The algorithm of choosing artifact version is given below :
- Explicitly set dependency version
- Version set in parent project
- Version in imported pom (order of import is important if there are more than one)
- Maven chooses version