Bill Of Materials concept came into being to resolve common maven dependency issues w.r.t versions. You might have encountered projects running into issues by mixing versions among spring dependencies. If we don’t declare dependencies explicitly either by skipping the certain third party versions from certain spring dependencies, we might run into unpredictable issues.
To overcome such issues, Maven came up with the concept of “bill of materials”- BOM dependency.
Spring provides support for BOM by providing spring-framework-bom. All we need to do is, declare following dependency in dependencyManagement.
With the below declaration, we are instructing maven to look for versions of the dependencies in the spring-framework-bom pom.xml. The only version we need to care about is, spring framework version.
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>4.2.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
In Dependencies section, include the required spring dependencies without version. All included spring dependencies will pull the version from spring-framework-bom pom.xml. This ensures all spring dependencies ( both direct and transitive) will be at version level required for corresponding spring framework version mentioned.
If we observe the dependencies section below, there is no mention of version for the declared dependencies. Because they are being derived from the Bill Of Materials(BOM) pom.xml that got added in pom.xml under dependency management tag.
<dependencies> <!-- Spring and Transactions --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> </dependency> </dependencies>
<dependencyManagement>will manage the required dependencies with all the details including version number.
<dependencies>tag outside of
<dependencyManagement>tag is used to include the dependencies to the corresponding project by deriving additional information of the corresponding dependency from dependencyManagement section.
For more details on maven dependencyManagement vs dependencies , please refer Maven dependencyManagement section.
Additional information on Maven
Bill Of Materials and how to create your own
bill of Materials can be found at Maven (Bill Of Materials) BOM .