DEV Community

Jan Cizmar for Tolgee

Posted on

Overriding dependency version in Spring Boot

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:

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.

Top comments (0)