Gangmax Blog

How to Make Gradle Use The Latest Version of A Dependency

In Gradle build script you can set the dependency version like below:

1
2
3
SLF4J_VERSION = 2.0.+
...
implementation 'org.slf4j:slf4j-api:${SLF4J_VERSION}'

It you do so, the Gradle build will download the latest build of “2.0.X”, let’s say currently it’s “2.0.1”, and use it to build the project.

However as time goes, if the dependency has a newer version like “2.0.2”, be default the Gradle build won’t know that so it will still used the cached local “2.0.1” version dependency to do the build. In this case, how could we force Gradle to get the lastest “2.0.2” vesion to build the project?

The answer comes from here. You can run the following command to force Gradle NOT to use the cache and download the latest dependency before building:

1
gradle clean build --refresh-dependencies

Comments