Skip to content

/flags/gradle/refresh-dependencies

gradle build --refresh-dependencies: ignore the dependency cache

The commands on this page have not been executed by our verification runner yet.updated
tool
Gradle
command
gradle
flag
--refresh-dependencies
default
off: cached module metadata is reused; dynamic and changing versions are re-checked after 24 hours

./gradlew build --refresh-dependencies tells Gradle to ignore cached entries for resolved modules and artifacts and to ask the repositories again for every dependency. Artifacts whose checksum has not changed are not downloaded again, but every module is re-validated, so the build is slower. Use it once when you suspect stale cached metadata: a new -SNAPSHOT that Gradle does not pick up, a 1.+ range that stays on an old version, or a repository fixed after a bad publish.

When it helps

SymptomWhy --refresh-dependencies helps
A new SNAPSHOT is not usedChanging modules are cached for 24 hours by default
latest.release or 1.+ resolves to an old versionDynamic versions are cached for 24 hours by default
Could not resolve after a repository outageGradle cached the missing result; refresh forces a new lookup
Metadata changed for the same version (bad publish fixed)Cached metadata is re-validated against the repository

Usage

bash
./gradlew build --refresh-dependencies
./gradlew :app:dependencies --configuration runtimeClasspath --refresh-dependencies

It is a per-invocation flag; there is no need to keep it in CI scripts.

Lighter alternatives

Instead of refreshing everything, shorten the cache time for the modules that change:

build.gradle
configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'   // SNAPSHOTs
    resolutionStrategy.cacheDynamicVersionsFor 10, 'minutes'  // 1.+, latest.release
}
FlagEffect
--refresh-dependenciesRe-validate all cached dependency metadata and artifacts
--offlineUse only the cache; fail if something is missing
--write-locksUpdate dependency lock files (with dependency locking enabled)
--no-build-cacheIgnore the build cache (task outputs), unrelated to dependencies

Sources