What is ~/.gradle/caches, and is it safe to delete?

The ~/.gradle/caches folder holds libraries, build outputs and transformed files that Gradle downloads or generates, and it is safe to delete because Gradle fetches them again on the next build.

Shiva ChandraMaker of Clean House · · 2 min read
Short answer

~/.gradle/caches is where Gradle stores downloaded dependencies, the local build cache and transformed files for Android and Java projects. It is safe to delete. Stop Gradle and quit Android Studio first, then remove the folder. The next build downloads dependencies again, so expect a slower first build.

Path
~/.gradle/caches
What it is
Downloaded dependencies, build cache and transformed artifacts used by Gradle
Typical size
Commonly 5 to 20 gigabytes on Android developer Macs; one real Mac had 11 GB here
Made by
Gradle (Android Studio, command-line builds)
Safe to delete?
Safe to clear
Comes back?
Yes. The first build afterward downloads dependencies again and is slower

What is in this folder?

Gradle's user home keeps global settings and logs next to the caches. The caches folder has version-specific subfolders and some shared ones such as modules-2 for downloaded libraries, transforms for processed files and build-cache-1 for the local build cache. The Gradle documentation says Gradle creates, uses and cleans these caches automatically, but only removes entries that went unused for a period.

In practice it still grows: every Gradle version, Android Gradle plugin and dependency version adds more. On the developer's own Mac, deleting ~/.gradle/caches (11 GB) and the Gradle wrapper downloads (724 MB) took free space from 2.2 GB to 14 GB.

Is it safe to delete?

Yes. It is a cache of things Gradle can download or recompute. Your code, build.gradle files and signing keys are not in it. The cost is a long first build and a full re-download of dependencies, so do it with a network connection.

Do not delete the whole ~/.gradle folder blindly. It can also hold gradle.properties with signing passwords and init.d scripts. Delete only caches.

How do I clear it by hand?

  1. Quit Android Studio and stop the Gradle daemons.
  2. Delete the caches folder.
  3. Open a project and sync. The first build downloads what it needs.
./gradlew --stop
rm -rf ~/.gradle/caches
Run ./gradlew --stop from any project folder that has a Gradle wrapper. Do not delete caches during a build, because it breaks the build in progress.

How do I stop it growing?

Gradle trims unused entries by itself, so the biggest wins come from removing old Gradle versions in ~/.gradle/wrapper/dists and clearing caches after big upgrades.

How Clean House handles it

Clean House lists ~/.gradle/caches as a Gradle cache that downloads again and moves the whole folder to the Trash as one unit. It treats ~/.gradle itself carefully: the parent folder is only offered when no gradle.properties or init.d is present, so signing keys are not swept up.

Questions

Is it safe to delete ~/.gradle/caches?

Yes. Gradle downloads dependencies and rebuilds its caches on the next build. Stop Gradle first.

How big is the Gradle cache?

Often many gigabytes. One developer Mac had 11 GB in ~/.gradle/caches.

Should I delete the whole ~/.gradle folder?

No. It can hold gradle.properties with credentials. Delete only the caches folder.

Does Gradle clean its own cache?

Partly. Gradle removes unused cache entries on a schedule, but the folder still grows large.

Sources

  1. Gradle Docs: Gradle user home directory layout
  2. Gradle Docs: Dependency caching