Overriding dependency version in Spring Boot

Jan Cizmar - Oct 14 '23 - - Dev Community

Do you know that feeling when you spend hours trying to do something without any luck and then you find out that the solution could not be easier? Well, that just happened to me. I was trying to upgrade the Hibernate version in our Spring boot app.

What doesn't work

I tried to exclude the dependency from spring boot and include the desired one the standard gradle way. With no luck...

    implementation ("org.springframework.boot:spring-boot-starter-data-jpa"){
        exclude group: 'org.hibernate.orm', module: 'hibernate-core'
        exclude group: "org.hibernate.orm", module: "hibernate-jpamodelgen"
    }
    implementation "org.hibernate:hibernate-core:$hibernateVersion"
Enter fullscreen mode Exit fullscreen mode

After hours of trying to diagnose why I always got the version included in Spring Boot, I found out that there is the Spring Boot dependency management plugin. That's the plugin which handles all the spring boot versions and enforces the versions defined by spring boot.

What works

Fortunately, there is a way to override the version. And it's super easy.

You just need to specify the version in your build.gradle.

ext['<dependency>.version'] = '6.0.9'
Enter fullscreen mode Exit fullscreen mode

or using properties.gradle:

spring-framework.version=6.0.9
Enter fullscreen mode Exit fullscreen mode

as stated here in the Spring docs.

And voilà! It works! You can find the list of the version properties you can override here.

Hope this helps future travelers who will struggle with the same.

Thanks for reading, and please consider using and staring Tolgee platform on GitHub ⭐️ - a tool healing your localization pain.

. . . . . . . . . . . . . . . . . . . . . . . . .