Configuring Gradle project to always refresh dependencies in the Gradle cache


(Vinod Sajja) #1

Is there a way to configure a Gradle project to always refresh dependencies in the Gradle cache (not using --refresh-dependencies)?


(Peter Niederwieser) #2
configurations.all {
    resolutionStrategy {
        cacheDynamicVersionsFor 0, "seconds"
        cacheChangingModulesFor 0, "seconds"
    }
}

For more information, see Fine-tuned control over dependency caching in the Gradle User Guide.


(Vinod Sajja) #3

Hmm, I tried setting cacheChangingModulesFor 0, “seconds” for my configuration and it didn’t seem to work.Here’s what I’m doing:

Component B depends on Component A version 1.0.

Resolving the configuration caches Component A version 1.0, great.

Component A version 1.0 is then updated in the repository to include an additional artifact. Resolving the configuration again doesn’t update Component A version 1.0 in the cache.

Using --refresh-dependencies does the trick. How does Gradle know the dependency has changed?


(Peter Niederwieser) #4

Did you mark the dependency as changing?

dependencies {
    compile("foo:bar:1.0") { changing = true }
}

(Vinod Sajja) #5

Works, thank you :slight_smile: