Below shows the hierarchy of my POMs.
You can see that we have a company parent-pom for spring boot projects. This POM has spring-boot-starter as it's parent, and it imports our own dependency-management BOM.
[INFO] --- hierarchy-maven-plugin:1.4:tree (default-cli) @ user-service ---
[INFO] PARENT com.MY_COMPANY.platform:user:3.20.14-SNAPSHOT
[INFO] PARENT com.MY_COMPANY.platform:spring-boot-parent:3.20.12-SNAPSHOT
[INFO] PARENT org.springframework.boot:spring-boot-starter-parent:1.5.12.RELEASE
[INFO] PARENT org.springframework.boot:spring-boot-dependencies:1.5.12.RELEASE <<<< This pom defines assertJ 2.x
[INFO] [ other imports ]
[INFO] IMPORT com.MY_COMPANY:dependencyManagementBase:2.23.14-SNAPSHOT <<<<<<<<<<<< This pom defines assertJ 3.x
[INFO] IMPORT com.MY_COMPANY.platform:platform-dependency-management:1.20.7
[INFO] ------------------------------------------------------------------------
To focus on a specific, we define AssertJ 3 in our dependency-management; however, spring-boot-dependencies defines AssertJ 2. Not a big deal with assertJ, but there are other fish like Mongo-Java-Driver that are not picking up our version.
How does Maven choose precedence here? Why doesn't our dependency-management win over a far-ancestor's dependency-management?
I also noticed that if I add AssertJ as a dependency of MY_COMPANY.platform:spring-boot-parent, it also does NOT use the version in our dependency-management (so I'll just keep it there for now, so the hierarchy under microscope is shorter).
EDIT - Add abbreviated POMs
com.MY_COMPANY.platform:spring-boot-parent
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.MYCOMPANY.platform</groupId>
<artifactId>spring-boot-parent</artifactId>
<version>3.20.12-SNAPSHOT</version>
<packaging>pom</packaging>
<prerequisites>
<maven>3.0.4</maven>
</prerequisites>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.12.RELEASE</version>
</parent>
<properties>
<MYCOMPANYdependencymanagement.version>2.23.13</MYCOMPANYdependencymanagement.version>
</properties>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.MYCOMPANY</groupId>
<artifactId>dependencyManagementBase</artifactId>
<version>${MYCOMPANYdependencymanagement.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
com.MY_COMPANY:dependencyManagementBase
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.MYCOMPANY</groupId>
<artifactId>dependencyManagementBase</artifactId>
<version>2.23.13</version>
<packaging>pom</packaging>
<modules>
<module>spring-dep-man</module>
</modules>
<properties>
<org.assertj-core.version>3.5.2</org.assertj-core.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${org.assertj-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
**EDIT 2 - Add verbose hierarchy showing different versions **
~/p/springbootparentpom> mvn hierarchy:tree -Dlevel=full
[INFO] --- hierarchy-maven-plugin:1.4:tree (default-cli) @ spring-boot-parent ---
[INFO] Displaying hierarchy.
[INFO] PARENT org.springframework.boot:spring-boot-starter-parent:1.5.12.RELEASE
[INFO] PARENT org.springframework.boot:spring-boot-dependencies:1.5.12.RELEASE
[INFO] DEP_MANAGEMENT ........
[INFO] DEP_MANAGEMENT org.assertj:assertj-core:2.6.0
[INFO] [ ... Many DEP_MAN and IMPORT ... ]
[INFO] IMPORT com.MYCOMPANY:dependencyManagementBase:2.23.14-SNAPSHOT
[INFO] DEP_MANAGEMENT ........
[INFO] DEP_MANAGEMENT org.assertj:assertj-core:3.5.2
[INFO] DEP_MANAGEMENT ........