/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
| Symptom | Why --refresh-dependencies helps |
|---|---|
| A new SNAPSHOT is not used | Changing modules are cached for 24 hours by default |
| latest.release or 1.+ resolves to an old version | Dynamic versions are cached for 24 hours by default |
| Could not resolve after a repository outage | Gradle 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
./gradlew build --refresh-dependencies
./gradlew :app:dependencies --configuration runtimeClasspath --refresh-dependenciesIt 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:
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds' // SNAPSHOTs
resolutionStrategy.cacheDynamicVersionsFor 10, 'minutes' // 1.+, latest.release
}| Flag | Effect |
|---|---|
| --refresh-dependencies | Re-validate all cached dependency metadata and artifacts |
| --offline | Use only the cache; fail if something is missing |
| --write-locks | Update dependency lock files (with dependency locking enabled) |
| --no-build-cache | Ignore the build cache (task outputs), unrelated to dependencies |
Sources
Related pages
commands · gradlegradle dependencies --configuration runtimeClasspath: show the dependency tree./gradlew dependencies prints the dependency tree per configuration; dependencyInsight explains why a version was chosen. How to read (*), (c) and -> markers.glossary · gradleWhat is the Gradle Wrapper (gradlew)?The Gradle Wrapper is a script plus a small JAR committed to a project that downloads and runs the exact Gradle version the build needs. How to use and upgrade.errors · gradleGradle: Unsupported class file major version 65Unsupported class file major version 65 means Gradle runs on a newer JDK (Java 21) than it supports. Upgrade the Gradle wrapper or run Gradle on an older JDK.flags · gradlegradle --offline: build with cached dependencies onlygradle --offline resolves dependencies and plugins only from the local cache. Preparing the cache, the No cached version error, refresh-dependencies, tuning.