Is it safe to delete Gradle’s caches in ~/.gradle?
- Yes, with Gradle stopped.
caches,wrapper/dists,jdksand the daemon logs are downloads and build data Gradle fetches or makes again. Keepgradle.propertiesandinit.d: those are your settings. - What it costs you: the next build downloads dependencies, and perhaps a Gradle distribution and a JDK, before it starts, so it runs slower that once.
- Does it come back? Yes. Gradle also prunes these folders itself, so clearing by hand is mainly for getting space back now.
- SiftMac’s verdict: Rebuilds
1. What’s in ~/.gradle
~/.gradle is the Gradle User Home, shared by every Gradle and Android project you build, from Terminal or from Android Studio and IntelliJ IDEA. Gradle’s docs list what lives there:
caches: downloaded dependencies (incaches/modules-2), transformed and compiled files, and caches tied to each Gradle version.wrapper/dists: complete Gradle distributions downloaded by./gradlew, one for each version your projects asked for.jdks: JDKs Gradle downloaded for toolchains.daemon: the registry and logs of Gradle daemons.gradle.propertiesandinit.d: your global properties and init scripts.
2. Where it is
~/.gradle
GRADLE_USER_HOME moves it. Each project also has its own .gradle folder and build output, covered further down.
3. How big it gets, and what Gradle prunes itself
du -sh ~/.gradle/* 2>/dev/null | sort -h
Gradle cleans its user home on its own, by default at most once every 24 hours, in the background when a daemon stops:
- Caches for a Gradle version nothing uses any more are deleted after 30 days of inactivity, or 7 days for snapshot versions.
- Files in the shared caches are deleted after 7 days unused if Gradle can recreate them locally, or after 30 days if they’d have to be downloaded again.
- Wrapper distributions no longer in use are deleted, and so are daemon logs older than 14 days.
So a large ~/.gradle usually means many projects, Gradle versions or JDKs in recent use, or a cleanup that someone switched off in an init script.
4. How to clear it safely
- Quit Android Studio or IntelliJ IDEA, and let running builds finish.
- Stop the daemons with
./gradlew --stopin a project, orgradle --stop. Each stops only daemons of its own Gradle version; others shut themselves down after 3 idle hours, andgradle --statuslists those of the current version. - Clear the caches, then look at which distributions you have.
./gradlew --stop
rm -rf ~/.gradle/caches/*
ls ~/.gradle/wrapper/dists
Delete a version folder in wrapper/dists only if no project still uses that Gradle version; otherwise that project’s next ./gradlew downloads it again. Leave gradle.properties, which can hold signing settings and repository credentials, and init.d alone.
In each project
A project’s build folder is its output: the clean task deletes the build directory, and the next build makes it again. The project’s .gradle folder is Gradle’s per-project cache, with build state for incremental builds and the configuration cache; it can go too, with Gradle stopped.
./gradlew clean
5. What the next build does
- Downloads every dependency again from your repositories, so it needs the network and takes longer. Builds with
--offlinefail until then, because they can’t fetch what’s missing. - Downloads the Gradle distribution if you removed its folder from
wrapper/dists, and a toolchain JDK if you clearedjdks. - Rebuilds the transformed and compiled files it had cached.
- Your source, build scripts and settings stay as they were.
Questions
Is it safe to delete the whole ~/.gradle folder?
Mostly, but it also deletes gradle.properties and init.d, which are your settings rather than cache. Clear caches, wrapper/dists and jdks instead.
Do I need to stop the Gradle daemon first?
Yes. Gradle shares its caches between running processes using lock files, so stop the daemons before removing files from under them. --stop takes a moment.
Can I make Gradle clean up sooner?
Yes, with an init script in ~/.gradle/init.d that shortens the retention periods. Gradle only reads cache cleanup settings from init scripts.
Does clearing ~/.gradle remove my Android emulators?
No. Emulators and the SDK live in ~/.android and ~/Library/Android/sdk; see Android emulators and the Android SDK.
How SiftMac handles it. Its Developer files category lists each project’s build and .gradle folders, next to a build.gradle or settings.gradle file, in projects you haven’t changed for 1, 3 or 6 months; none is ticked until you tick it. SiftMac doesn’t clear ~/.gradle itself: the space map shows its size and notes that the dependencies download again on the next build.
Download SiftMac · scanning is free, and so is your first 2 GB of cleaning · See how it works