Maven BOM (Bill of Materials)

Transitive dependencies are those that are not defined explicitly in pom.xml, but are used by dependencies defined in pom.xml. Versions conflicts can occur when different dependencies “include” different versions of the same artifact. In this case the closest dependency in dependency tree will be chosen. For instance,

(A→B→C→D 1.4 and A→E→D 1.2) : D 1.2 will be chosen as it is closer to A in dependency tree.

Aiming to avoid predicaments with dependency versions, Maven supports bom-dependencies concepts. For example, spring-framework-bom in <dependencyManagement>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.3.8.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

guarantees that all spring dependencies will be of the same version. Hence, version must not be pointed when adding dependency :

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
</dependencies>

Previous

Leave a Reply

Your email address will not be published. Required fields are marked *