Gradle cache too big? How to clear ~/.gradle safely
Gradle puts almost everything in one folder in your home directory: ~/.gradle. It is shared by every Gradle and Android project on your Mac, it only grows, and it is often one of the biggest folders on a developer machine.
What is inside
du -sh ~/.gradle/* | sort -rh
You will usually see these:
| Folder | What it holds | Safe to clear? |
|---|---|---|
caches |
Downloaded dependencies and build caches | Yes |
wrapper/dists |
The Gradle versions your projects’ wrappers downloaded | Yes, old versions download again when needed |
daemon |
Logs and state of the Gradle daemons | Yes, once the daemons are stopped |
gradle.properties |
Your global settings | Keep |
init.d |
Your global init scripts | Keep |
Stop the daemons first
Gradle keeps background processes, called daemons, that hold files open. Stop them before you delete anything. From any Gradle project:
./gradlew --stop
Clear the caches
rm -rf ~/.gradle/caches
On the next build, Gradle downloads the dependencies it needs again, so the first build is slow and needs internet. In Android Studio, a Sync will do the same.
Remove old Gradle versions
Every project that uses the Gradle wrapper downloads its own Gradle version. List them:
ls ~/.gradle/wrapper/dists
Delete the versions you no longer use, or the whole dists folder:
rm -rf ~/.gradle/wrapper/dists
A project will download the version it needs the next time you build it.
Keep your configuration
Do not delete gradle.properties or init.d. Those hold settings you may have written yourself, such as proxy settings, memory options or credentials for private repositories. They are small and not the problem. If you want to wipe ~/.gradle completely, copy those two first.
Newer Gradle cleans up a little by itself
Recent Gradle versions remove cache entries they have not used for some time. It slows the growth. It does not stop it, because the cache fills up every time you open a new project or switch versions.
What it costs
- A slower next build and a download of your dependencies.
- No access to dependencies if you build offline right after clearing.
- Your code and project files are not touched.
For Android developers
If you use Android Studio, Gradle is only one of the heavy folders. The SDK and emulators are bigger. See Android Studio using too much space. For the rest of a developer Mac, use the full checklist.
Quick answers
Is it safe to delete ~/.gradle/caches?
Yes. It holds downloaded dependencies and build caches that Gradle fetches again. The next build is slower and needs a network connection.
Can I delete the whole ~/.gradle folder?
You can, but you would lose your own configuration such as gradle.properties and init scripts. Deleting only caches and old wrapper versions is safer.
Do I need to stop Gradle first?
Yes. Run ./gradlew --stop so no daemon is using the files while you delete them.