How do i override spring dependency in gradle (kotlin) file? I'm using spring boot version `2.4.4` w...
r
How do i override spring dependency in gradle (kotlin) file? I'm using spring boot version
2.4.4
which has
2.4.4
vesrion of
spring-boot-starter-data-redis
I want to use
2.4.7
version of it and tried following lines but it's not working
implementation("org.springframework.boot:spring-boot-starter-data-redis:2.4.7")
it says
Could not find org.springframework.boot:spring-boot-starter-data-redis:2.4.7.
Required by:
project :
I've also tried adding following line to build.gradle file with no luck
extra["spring-data-redis.version"] = "2.4.7"
s
It doesn’t look like there’s a
2.4.7
version of
spring-boot-starter-data-redis
. Perhaps you’re looking for
spring-data-redis
? The
extra[…]
block is how I’ve done it for other dependencies, but you could try running
gradle dependencies
to see if something else is bringing in the lower version?
r
Yes, i want to use
spring-data-redis 2.4.7
How should i use that?
s
In your comment it says you tried
implementation("org.springframework.boot:spring-boot-starter-data-redis:2.4.7")
but maybe what you want is
implementation("org.springframework.boot:spring-data-redis:2.4.7")
?
r
So i should entirely remove
implementation("org.springframework.boot:spring-boot-starter-data-redis:2.4.7")
?
s
Yeah since there is no 2.4.7 for
spring-boot-starter-data-redis
r
One last dumb question,
spring-data-redis
will provide all features of
spring-boot-starter-data-redis
correct? i mean no build failure?
s
It doesn’t, I’m not sure how your project is structured. Perhaps you could try:
Copy code
implementation("org.springframework.boot:spring-boot-starter-data-redis:2.4.4")
implementation("org.springframework.boot:spring-data-redis:2.4.7")
I think ideally you’d want to use the
extra[...]
block you shared but perhaps the name is incorrect.
And then run
gradle dependencies
to make sure everything looks 👌
https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-dependency-versions.html According to this it looks like your extra block should have worked, so perhaps another dependency that is keeping the version below what you want
You might need the dependency management plugin?
Copy code
plugins {
      id("io.spring.dependency-management")
}
r
I've that plugin. i've used
Copy code
implementation("org.springframework.boot:spring-data-redis:2.4.7")
but it still says
Copy code
Could not find org.springframework.boot:spring-boot-starter-data-redis:2.4.7.
Required by:
    projec
s
Right. There is no
spring-boot-starter-data-redis
version
2.4.7
According to https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis the latest version is
2.4.4
so that needs to stay
My suggestion was to try to declare an additional dependency, the starter (2.4.4) + the version of spring-data-redis that you want (2.4.7) if the
extra
thing was not working:
Copy code
implementation("org.springframework.boot:spring-boot-starter-data-redis:2.4.4")
implementation("org.springframework.boot:spring-data-redis:2.4.7")
build.gradle.kts
gradle dependencies
m
Complete aside. I'd suggest migrating to Gradle platform rather than relying on the old Spring Dependency Management plugin. More consistent version resolution, and more intuitive, as you can use Gradle features for controlling versions rather than 'hack' of dependency management plugin. It's documented in Spring Boot docs alongside dependency management plugin info.
s
Do you happen to have a link? Definitely not completely happy with the dependency management plugin so would be nice to explore an alternative 😄
m
Sorry, on phone, so no. There's some info in spring docs when you goto boot gradle plugin. Newer versions show dependency management plugin, but also show Gradle platform approach. There's a great blog post that discusses it, too. Found link in another Workspace. https://nexocode.com/blog/posts/spring-dependencies-in-gradle/
🙏 1
s
This is awesome, thanks for sharing again will definitely share this with my team as well
500 Views