If you develop Android apps, Spring Boot projects, or any JVM-based application using Gradle, your ~/.gradle directory is silently growing every day. Between cached dependencies, wrapper distributions, daemon logs, and build cache entries, Gradle can easily consume 10-50GB of your Mac's SSD.
This guide covers every location where Gradle stores data on macOS and shows you exactly how to reclaim that space safely.
- 1. Audit Your Gradle Disk Usage
- 2. Clean the Dependency Cache
- 3. Remove Old Wrapper Distributions
- 4. Clear the Gradle Build Cache
- 5. Clean Daemon Logs and Data
- 6. Android Studio Specific Cleanup
- 7. Find build/ Directories Across Projects
- 8. Configuration Cache
- 9. Automate Gradle Cleanup | CocoaPods Cache Cleanup | npm/Yarn/pnpm Cleanup
- 10. Prevent Cache Bloat
- Complete Cheatsheet
1. Audit Your Gradle Disk Usage
Before cleaning anything, see where your space is going:
# Total ~/.gradle size
du -sh ~/.gradle
# Breakdown by subdirectory
du -sh ~/.gradle/* 2>/dev/null | sort -hr
# Top-level summary
du -sh ~/.gradle/caches
du -sh ~/.gradle/wrapper
du -sh ~/.gradle/daemon
du -sh ~/.gradle/build-scan-data
du -sh ~/.gradle/configuration-cache
Typical output on a developer machine:
| Directory | Typical Size | What It Contains |
|---|---|---|
| ~/.gradle/caches | 5-30GB | Downloaded JARs, metadata, transforms |
| ~/.gradle/wrapper/dists | 1-5GB | Full Gradle distributions (one per version) |
| ~/.gradle/daemon | 500MB-2GB | Daemon logs, registry files |
| ~/.gradle/build-scan-data | 100MB-1GB | Build scan upload data |
| ~/.gradle/configuration-cache | 100MB-500MB | Configuration cache entries |
| Project build/ dirs | 2-20GB each | Compiled output, APKs, test reports |
2. Clean the Dependency Cache
The ~/.gradle/caches directory is usually the biggest culprit. It contains:
- modules-2/files-2.1/ -- actual downloaded JAR files organized by group/artifact/version
- transforms-*/ -- transformed artifacts (dexing, desugaring for Android)
- jars-*/ -- processed JAR metadata
- journal-1/ -- cache bookkeeping
Safe: Use Gradle's built-in cleanup
# Stop all running Gradle daemons first
./gradlew --stop
# Or stop all Gradle processes
pkill -f "GradleDaemon"
# Clean the project build directory
./gradlew clean
Moderate: Remove old cache entries
# Remove caches older than 30 days
find ~/.gradle/caches -maxdepth 1 -type d -mtime +30 -exec rm -rf {} +
# Remove old transform caches
rm -rf ~/.gradle/caches/transforms-*
# Remove file-lock leftover files
find ~/.gradle/caches -name "*.lock" -delete
Aggressive: Nuclear the entire cache
# Remove all cached dependencies (they will re-download on next build)
rm -rf ~/.gradle/caches
3. Remove Old Wrapper Distributions
Each project can specify a different Gradle version in gradle-wrapper.properties. Gradle downloads the full distribution (~130MB each) and keeps every version forever.
# See all downloaded Gradle versions
ls -la ~/.gradle/wrapper/dists/
# Check total wrapper size
du -sh ~/.gradle/wrapper/dists/*
# Example output:
# 135M gradle-7.6.3-bin
# 285M gradle-8.0-all
# 135M gradle-8.5-bin
# 285M gradle-8.7-all
# 135M gradle-8.9-bin
# 285M gradle-8.12-all
If you have 10+ versions, that is 1.5-3GB just in wrapper distributions.
# Remove all old wrapper distributions
rm -rf ~/.gradle/wrapper/dists
# Or keep only the latest -- remove specific old versions
rm -rf ~/.gradle/wrapper/dists/gradle-7.*
rm -rf ~/.gradle/wrapper/dists/gradle-8.0*
rm -rf ~/.gradle/wrapper/dists/gradle-8.1*
4. Clear the Gradle Build Cache
Gradle's build cache stores task output to avoid re-running unchanged tasks. It grows with every project variation.
# Check build cache size
du -sh ~/.gradle/caches/build-cache-1
# Clear the build cache via Gradle
./gradlew --build-cache clean
# Or delete it directly
rm -rf ~/.gradle/caches/build-cache-1
Shared build cache (CI scenarios)
If you set up a shared build cache, also check:
# Gradle's local build cache (default location)
du -sh ~/.gradle/caches/build-cache-*
# If using Gradle Enterprise / Develocity cache
du -sh ~/.gradle/build-scan-data
5. Clean Daemon Logs and Data
Gradle runs a background daemon for faster builds. Each Gradle version maintains its own daemon data:
# Check daemon directories
du -sh ~/.gradle/daemon/*
# Example output: one directory per Gradle version
# 250M ~/.gradle/daemon/7.6.3
# 300M ~/.gradle/daemon/8.5
# 350M ~/.gradle/daemon/8.9
# Stop all daemons
./gradlew --stop
# Remove old daemon data
rm -rf ~/.gradle/daemon
# Or just remove old version daemons
find ~/.gradle/daemon -maxdepth 1 -type d -name "7.*" -exec rm -rf {} +
6. Android Studio Specific Cleanup
Android development with Gradle creates additional caches beyond ~/.gradle:
# Android SDK build tools
du -sh ~/Library/Android/sdk/build-tools/*
# Android emulators
du -sh ~/.android/avd/*
# Android Studio caches
du -sh ~/Library/Caches/Google/AndroidStudio*
# Kotlin compiler daemon and caches
du -sh ~/.kotlin
# Maven local cache (Gradle also uses this)
du -sh ~/.m2/repository
Clean Android-specific caches
# Remove old Android Gradle Plugin caches
rm -rf ~/.android/.gradle
# Remove Android Studio caches
rm -rf ~/Library/Caches/Google/AndroidStudio*
# Remove old build tool versions (keep latest)
ls ~/Library/Android/sdk/build-tools/
# Then remove old ones via Android Studio SDK Manager
# Clean Kotlin daemon cache
rm -rf ~/.kotlin/daemon
# Clean Maven local repository
rm -rf ~/.m2/repository
7. Find build/ Directories Across Projects
Every Gradle project has a build/ directory with compiled output. In multi-module projects, each submodule has its own build/ directory.
# Find all Gradle build directories in your projects folder
find ~/Projects -name "build" -type d -prune 2>/dev/null | head -20
# Check total size of all build dirs
find ~/Projects -name "build" -type d -prune -exec du -sh {} + 2>/dev/null | sort -hr | head -20
# One-liner: find and display total
find ~/Projects -name "build" -type d -prune -exec du -sk {} + 2>/dev/null | awk '{sum+=$1} END{printf "Total: %.1f GB\n", sum/1048576}'
For Android projects specifically, APK and AAB outputs can be surprisingly large:
# Find APK files
find ~/Projects -name "*.apk" -exec du -sh {} + 2>/dev/null | sort -hr
# Find AAB files
find ~/Projects -name "*.aab" -exec du -sh {} + 2>/dev/null | sort -hr
Clean all build directories at once
# Remove all build/ directories under Projects (careful!)
find ~/Projects -name "build" -type d -prune -exec rm -rf {} +
# Or clean via Gradle for each project
for dir in ~/Projects/*/; do
if [ -f "$dir/gradlew" ]; then
echo "Cleaning $dir..."
(cd "$dir" && ./gradlew clean 2>/dev/null)
fi
done
8. Configuration Cache
Gradle 8+ introduced the configuration cache, which stores serialized task configurations. It lives at:
# Global configuration cache
du -sh ~/.gradle/configuration-cache
# Per-project configuration cache
du -sh ~/Projects/*/.gradle/configuration-cache 2>/dev/null
# Clean global configuration cache
rm -rf ~/.gradle/configuration-cache
# Clean per-project caches
find ~/Projects -path "*/.gradle/configuration-cache" -type d -exec rm -rf {} + 2>/dev/null
# Find and size all per-project .gradle dirs
find ~/Projects -maxdepth 2 -name ".gradle" -type d -exec du -sh {} + 2>/dev/null | sort -hr
9. Automate Gradle Cleanup
Gradle 8+ includes automatic cache cleanup, but you can also set up your own schedule:
Configure Gradle's built-in cleanup
Add to ~/.gradle/init.d/cache-settings.gradle:
// Reduce cache retention from default 30 days
beforeSettings {
caches {
releasedWrappers { removeUnusedEntriesAfterDays = 14 }
snapshotWrappers { removeUnusedEntriesAfterDays = 7 }
downloadedResources { removeUnusedEntriesAfterDays = 14 }
createdResources { removeUnusedEntriesAfterDays = 14 }
}
}
Create a cleanup script
#!/bin/bash
# gradle-cleanup.sh -- Safe Gradle cache cleanup
echo "=== Stopping Gradle daemons ==="
pkill -f GradleDaemon 2>/dev/null
sleep 2
BEFORE=$(du -sk ~/.gradle 2>/dev/null | awk '{print $1}')
echo "=== Cleaning old wrapper distributions ==="
find ~/.gradle/wrapper/dists -maxdepth 1 -type d -mtime +60 -exec rm -rf {} + 2>/dev/null
echo "=== Cleaning old caches ==="
rm -rf ~/.gradle/caches/transforms-* 2>/dev/null
rm -rf ~/.gradle/caches/build-cache-* 2>/dev/null
find ~/.gradle/caches -name "*.lock" -delete 2>/dev/null
echo "=== Cleaning daemon data ==="
find ~/.gradle/daemon -maxdepth 1 -type d -mtime +30 -exec rm -rf {} + 2>/dev/null
echo "=== Cleaning build scan data ==="
rm -rf ~/.gradle/build-scan-data 2>/dev/null
echo "=== Cleaning configuration cache ==="
rm -rf ~/.gradle/configuration-cache 2>/dev/null
AFTER=$(du -sk ~/.gradle 2>/dev/null | awk '{print $1}')
SAVED=$(( (BEFORE - AFTER) / 1024 ))
echo "=== Done! Freed ${SAVED}MB ==="
Automate with cron or launchd
# Run cleanup every Sunday at 3am
echo "0 3 * * 0 /bin/bash ~/scripts/gradle-cleanup.sh >> ~/gradle-cleanup.log 2>&1" | crontab -
brew tap bysiber/cleardisk && brew install --cask cleardisk
10. Prevent Cache Bloat
Use -bin instead of -all distributions
In each project's gradle/wrapper/gradle-wrapper.properties, change:
# BEFORE (includes source + docs, ~285MB)
distributionUrl=https\://...gradle-8.12-all.zip
# AFTER (binary only, ~135MB)
distributionUrl=https\://...gradle-8.12-bin.zip
Standardize Gradle versions across projects
Using 5 different Gradle versions means 5 separate wrapper downloads and 5 daemon processes. Update older projects to use the same recent Gradle version where possible.
Keep only needed SDK versions
In Android Studio, go to Settings > Android SDK > SDK Platforms and uninstall old API levels you no longer target. Same for SDK Tools -- remove old build tool versions.
Use Gradle's --no-build-cache flag for CI
# Disable build cache to keep local disk clean
./gradlew build --no-build-cache
# Or in gradle.properties
org.gradle.caching=false
Complete Gradle Disk Cleanup Cheatsheet
# === AUDIT ===
du -sh ~/.gradle # total Gradle home
du -sh ~/.gradle/* 2>/dev/null | sort -hr # breakdown
du -sh ~/.gradle/caches # dependency cache
du -sh ~/.gradle/wrapper/dists # wrapper downloads
du -sh ~/.gradle/daemon # daemon data
du -sh ~/.m2/repository # Maven local repo
# === STOP DAEMONS FIRST ===
./gradlew --stop
pkill -f GradleDaemon
# === SAFE CLEANUP ===
./gradlew clean # clean project build/
rm -rf ~/.gradle/caches/build-cache-* # clear build cache
rm -rf ~/.gradle/caches/transforms-* # clear transforms
rm -rf ~/.gradle/build-scan-data # clear scan data
# === MODERATE ===
rm -rf ~/.gradle/daemon # clear daemon data
rm -rf ~/.gradle/configuration-cache # clear config cache
rm -rf ~/.gradle/wrapper/dists/gradle-7.* # old wrappers
# === AGGRESSIVE ===
rm -rf ~/.gradle/caches # remove ALL caches
rm -rf ~/.gradle/wrapper/dists # remove ALL wrappers
# === NUCLEAR ===
rm -rf ~/.gradle # remove everything
# === ANDROID EXTRAS ===
rm -rf ~/Library/Caches/Google/AndroidStudio*
rm -rf ~/.android/.gradle
rm -rf ~/.kotlin/daemon
rm -rf ~/.m2/repository
# === FIND ALL build/ DIRS ===
find ~/Projects -name "build" -type d -prune -exec du -sh {} + 2>/dev/null | sort -hr
Frequently Asked Questions
How much space can I recover from Gradle caches?
Typically 10-50GB depending on the number of projects and Gradle versions used. Android developers tend to see the largest caches because of the additional transforms, SDK tools, and emulator images.
Is it safe to delete ~/.gradle/caches?
Yes. The caches directory contains only downloaded dependencies and derived data. Gradle re-downloads everything on the next build. Your first build will take longer as it re-downloads all JARs, but nothing breaks permanently.
Why does Gradle keep so many versions?
Each project can specify its own Gradle version via the wrapper. Gradle never deletes old versions automatically (prior to version 8). If you work on 10 projects, you may end up with 10 different Gradle distributions cached.
What about ~/.m2/repository?
The Maven local repository at ~/.m2/repository is shared between Gradle and Maven. If you only use Gradle, you can safely delete it. Gradle may have published some local artifacts there via mavenLocal(), so check your build scripts first.
Does Gradle 8 clean up automatically?
Yes, Gradle 8+ includes automatic cache cleanup that removes unused entries after 30 days. However, this only applies to the version of Gradle currently running. Caches from older Gradle versions still accumulate. You can customize the retention period via the init script shown in the automation section.
How often should I clean?
A monthly cleanup of transforms and build cache is a good baseline. For the full dependency cache, quarterly cleanup is sufficient since re-downloading everything takes time. Or use ClearDisk to automate it with one click.