Pratik Joshi
Pratik Joshi

Reputation: 258

How to inherit dependency version from required BOM POM in maven spring boot project?

I am new to spring boot world and encountered with an issue. I have a requirement of using mssql in my project which I am default getting as a dependency from spring-boot-starter-parent but the catch is the version which is getting inherited is what i do not want.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
    <type>pom</type>
</dependency>

This will give me mssql version mssql-jdbc : 6.1.0.jre7 (Which i do not want)

My organization has a dedicated BOM POM created for all the common components used in all the projects which includes mssql latest version. mssql-jdbc :8.4.1.jre8

I have declare this BOM POM under dependencyManagement tag.

<dependencyManagement>
  <dependencies> 
    <dependency>
     <grpId></grpId>
     <artifactiID></>
     <version/>
     </dependency>
   </dependencies>
</dependencyManagement>

Now my POM is only taking mssql version from spring boot parent (Which is obvious as per the tree hierarchy) but i want to use version from BOM POM.

I also don't want to hardcode the mssql version in my pom dependency like

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>It should take from the BOM POM declared in dependency management</version>

So that whenever a new version got updated in my BOM POM, it should reflect directly in my application POM file.

my question can be repetitive or easy to figure out but as i am new to the spring world, Your help will be helpful for sure.

Thanks is advance.

Upvotes: 1

Views: 1251

Answers (2)

akuma8
akuma8

Reputation: 4691

To override the version of a dependency you have to find how it was defined in the parent POM. Example in your case, if you look at the Spring Boot parent POM, in the <properties> section, you should see something like:

<mssql.version>Y.XX</mssql.version> <!-- please note that I am not really sure about the property name but I am 100% that the version is defined as a property-->

Then copy-paste that property in the <properties> section of your POM and set the version you want.

Upvotes: 0

J Fabian Meier
J Fabian Meier

Reputation: 35795

Not possible.

Parent POM versions are stronger than BOM versions.

You need to add the version explicitly in your POM and change it manually when the BOM changes.

Upvotes: 1

Related Questions