28

I build an own library that I deploy on a nexus repository. This snapshot is changed very often, therefore not every change gets a new version number. My problem is that I don't get the newest code without changing the version number in project that use this library. I tried "--refresh-dependencies" and I also tried to clear the dependency from the cache by deleting the folder of this dependency under "\caches\modules-2\files-2.1\my.dependency"
I also tried this:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

Has anyone an idea how I can force grade to download the newest status of a dependency despite the version number didn't change?

3

2 Answers 2

59

First make sure your snapshot has the right version format:

dependencies {
    compile group: "groupId", name: "artifactId", version: "1.0-SNAPSHOT"
}

If you have not used the -SNAPSHOT suffix (or you are not using a Maven repository), you have to indicate that your dependency is changing:

dependencies {
    compile group: "groupId", name: "artifactId", version: "1.0", changing: true
}

Then you have to tell Gradle not to cache changing dependencies, otherwise it will only update them every 24 hours:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

In case you have also configured the dependency as a dynamic version like this:

dependencies {
    compile group: "groupId", name: "artifactId", version: "1+", changing: true
}

Then you have to add:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
    resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
}

Note that this might slow your build a lot.

If this doesn't help, remove the relevant parts of .gradle directory, or simply the whole directory again.

If that doesn't help neither, I am afraid it will be an issue on your repository side.

9
  • Ok deleting the .gradle directory worked. But actually this wasn't the solution I was looking for. I thought gradle would offer possibilities to do that by build.gradle. Okay, but better than nothing.
    – n00bst3r
    Feb 6, 2017 at 18:59
  • 1
    @Thunderforge true, I should update the answer. Next time feel free to edit it to fix any misconceptions, thanks. Feb 21, 2017 at 22:04
  • 2
    @n00bst3r check your repositories config. The mavenLocal() needs to be below your internal repo manager to find the update snapshot.
    – S T
    Sep 21, 2018 at 15:25
  • 2
    In above answer this line (or you are not using a Maven repository), so will it not work for non-maven repository? We are using jfrog artifactory and following the convention of :0.0.1-SNAPSHOT, but still gradle picks from cache and not latest. any solution?
    – rhozet
    Nov 29, 2018 at 3:53
  • 2
    i'm having the same issue with Jfrog repository Sep 22, 2020 at 8:05
1

You can use

./gradlew --refresh-dependencies run

to start the application and refresh all dependencies.

Source: https://docs.gradle.org/current/userguide/dynamic_versions.html (via a comment above by @Dmitriy Pichugin).

The --refresh-dependencies option tells Gradle to ignore all cached entries for resolved modules and artifacts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.