How to clear the Gradle cache
Codemia Knowledge Hub ·
To clear the Gradle cache, stop the daemon with ./gradlew --stop (it holds file locks on cached artifacts), then delete ~/.gradle/caches/. For project build output, run ./gradlew clean. Picking the right cache to clear avoids full wipes that add minutes to your next build.
Where Gradle keeps its caches
Gradle has several cache directories with different jobs. Clearing the wrong one either does nothing or forces a much longer rebuild than needed.
| Directory | What it caches | Safe to delete? | Rebuild cost |
~/.gradle/caches/modules-2/ | Downloaded dependencies (JARs, POMs) | Yes | Re-downloads all dependencies |
~/.gradle/caches/transforms-3/ | Transformed artifacts | Yes | Re-runs artifact transforms |
~/.gradle/caches/build-cache-1/ | Task output cache | Yes | Re-executes previously cached tasks |
~/.gradle/wrapper/dists/ | Gradle distributions | Yes (rarely needed) | Re-downloads the Gradle wrapper |
<project>/.gradle/ | Project-level task history | Yes | Invalidates incremental builds |
<project>/build/ | Compiled classes, JARs, reports | Yes | Full recompile of the project |
Delete the whole global cache
The most thorough option removes all downloaded dependencies, cached transforms and build cache entries:
The next build re-downloads every dependency and re-runs every task, which can add several minutes on a project with hundreds of dependencies.
Clear only the dependency cache
For a corrupted or stale dependency, target the module cache:
Use this for errors like "Could not resolve artifact" or when a dependency resolves to the wrong version even though the build file is correct.
Clean the project build directory
For stale compiled classes or outdated generated code, clean is enough:
This leaves the global cache alone. Dependencies stay cached and only compiled output is regenerated.
Invalidate the build cache
The build cache stores task outputs keyed by inputs. If you suspect it is returning wrong results (rare, but possible after Gradle upgrades or plugin changes):
cleanBuildCache is not a built-in task in current Gradle versions, so the command only works if a plugin or your build defines it. Deleting build-cache-1/ directly works everywhere.
Stop the Gradle daemon
The daemon is a long-running process that keeps project information in memory. If phantom build issues survive clearing disk caches, its in-memory state may be stale:
On Windows you must also stop the daemon before deleting cache directories, because it holds file locks that block deletion.
Refresh dependencies without deleting the cache
If a SNAPSHOT dependency changed upstream, force Gradle to re-check remote repositories:
This is faster than a full clear because only dependencies whose checksums changed are downloaded.
Configuring cache behavior
Control caching in gradle.properties or settings.gradle:
A custom build cache directory is set in settings.gradle, not in gradle.properties:
Which cache to clear for each symptom
Mistakes when clearing the Gradle cache
- Deleting all of
~/.gradle/instead ofcaches/.wrapper/dists/holds downloaded Gradle distributions, and re-downloading them is slow and unnecessary.~/.gradle/gradle.propertiesholds your global configuration. - Not stopping the daemon on Windows. Its file locks cause partial deletions and "Access denied" errors. Run
./gradlew --stopfirst. - Relying on a
cleanBuildCachetask. Gradle does not ship one; delete the directory or use--no-build-cache. - Running
--refresh-dependencieson every build. It contacts remote repositories for every dependency each time and slows builds significantly. Treat it as a one-time fix. - Wiping global caches for a single-module problem. Clearing caches invalidates Gradle's input/output hash tracking and forces full recompilation. Use
./gradlew :module:cleaninstead. - Clearing caches in CI without updating the cache restore step. Many CI systems (GitHub Actions, GitLab CI) cache
~/.gradle/caches/between runs; clear it without updating that configuration and every later run starts cold.
Related reading
- How to clear or clean specific pod from the local cocoapods cache
- How to clear react-native cache?
- How to combine sharding and consistent hashing within a distributed system?
- How to configure Kafka to behave like a FiFo queue?
- How to clear the console using Java?
- How to clone an InputStream?
- How to configure RabbitMQ using Active/Passive High Availability architecture
- how to configure redis ttl with spring boot 2.0
System design interview problems on this topic
- Design a Key Value Store: solution and walkthrough
- Design a Distributed Unique Id Generator: solution and walkthrough
- Design a Distributed Locking System: solution and walkthrough
- Design a Distributed Counter: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.