Tell gradle not to cache snapshot dependencies (cacheChangingModulesFor 0 doesn't work as expected)


(Ingo Besenfelder) #1

Hi gradle team and users,

I’m running Gradle 3.0 with JFrog Artifactory. I use the ArtifactoryPlugin and DependencyManagement plugin, as well as eclipse, java and maven-publish.

I have a problem with the caching of snapshot (changing module) dependencies.
Although I have set the following, snapshots are NOT updated on every build:

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

with this dependency:
compile ('mygroup:lib:1.0.0-SNAPSHOT') { changing = true }
(I know { changing = true } is redundant since implied by -SNAPSHOT, but I put it anyway. It shouldn’t make a difference here.)

The following happens:
1.) Deploy lib.jar-1.0.0-20160922.060203-1.jar to Artifactory
2.) gradle build => downloads lib.jar-1.0.0-20160922.060203-1.jar
<== good so far.
3.) Deploy lib.jar-1.0.0-20160922.060203-2.jar to Artifactory (xxx-1.jar still exists in Artifactory)
4.) gradle build => downloads lib.jar-1.0.0-20160922.060203-1.jar
<== This is wrong in my opinion. Gradle still sticks with the outdated version. Why?
5.) Artifactory cleans itself, so that only the newest SNAPSHOT (xxx-2.jar) exists (xxx-1.jar does not exist in Artifactory anymore).
6.) gradle build => tries to download lib.jar-1.0.0-20160922.060203-1.jar and FAILS
<== This is the same problem with worst case result (=build fails).
7.) Now I delete “~.gradle\caches\modules-2\metadata-2.17\descriptors\mygroup\jar\1.0.0-SNAPSHOT” manually. Which means, I delete the metadata for the “xxx-1.jar”.
8.) gradle build => downloads lib.jar-1.0.0-20160922.060203-2.jar
<== It seems that the jar itself is not cached (as expected), but the metadata (~pom) is cached (not expected, leads to error). Is this a bug, or am I doing something wrong here?

PS: gradle build --refresh-dependencies is working as expected and downloads the new and up2date “-2.jar”.
<== why does this work as expected and the cacheChangingModulesFor 0, 'seconds' does not?


(Chris Doré) #2

Did you try the caching option for dynamic modules? I’m not certain, but I think snapshots might not fall into the changing modules category.


(Ingo Besenfelder) #3

Hi Chris,
thanks for the reply!
The Gradle User Guide states the following:

An example of this type of changing module is a Maven SNAPSHOT module, which always points at the latest artifact published.

So SNAPSHOTs are changing modules and the above usage should be fine in my opinion.
Besides that, I did try the same for dynamic versions cacheDynamicVersionsFor 0, 'seconds' which didn’t do anything with the snapshots.

I have to say, I am a bit disappointed by the number of replies in this forum compared to other far less popular tools communities. Can I do anything about this? Did I post this issue in the wrong place or something?


(Iva Jelencic) #4

I am experiencing the same issue. The only thing that helps is a forced command line --refresh-dependencies which is unfortunate.


(Ron) #5

@ibesenfelder, @Chris_Dore I’m facing the exact same issue with Gradle 4.2. Has there been any progress since Sep '16? Could it be resolved?


(nick heniser) #6

Yes, I am having similar problems with 4.3.1, gradle will not pull the latest snapshot regardless if I set the caching strategy.


(nick heniser) #7

I figured out my issue! I have a multi-project build, and I didn’t have the ‘configurations.all{ … }’ block in my allprojects block. I added it there, and voila, latest snapshot downloaded on gradle-> refresh