DevCleaner
Menu
Skip to content
Browse guides

How to Clear the Gradle Cache on Mac and Linux

Gradle keeps downloaded dependencies, build cache entries, compiled build scripts and whole Gradle distributions in one folder in your home directory. ./gradlew clean does not touch any of it. That task only deletes the build folder of the project you run it in. This guide shows what is in the shared Gradle folder, how to measure it, and how to clear one part or all of it without breaking your next build.

On this page

Where the Gradle cache lives

Gradle calls this folder the Gradle User Home. On macOS and Linux it is ~/.gradle unless the GRADLE_USER_HOME environment variable points somewhere else. Android Studio and IntelliJ IDEA can also set a different Gradle user home in their Gradle settings, so check there if ~/.gradle looks empty.

echo "${GRADLE_USER_HOME:-$HOME/.gradle}"

The parts that take space:

FolderWhat it holdsAfter you delete it
caches/modules-2Downloaded dependencies: JARs, POMs and metadataThe next build downloads them again
caches/build-cache-1Local build cache: task outputs keyed by their inputsTasks run again instead of loading from the cache
caches/transforms-*, caches/jars-*Artifact transform outputs and instrumented JARsGradle recreates them
caches/<version> (for example caches/9.8.2)Compiled build scripts and generated JARs for one Gradle versionRecreated the next time that version runs
wrapper/distsFull Gradle distributions downloaded by ./gradlewThe wrapper downloads its version again
daemonDaemon registry and log filesGradle starts fresh daemons and new logs
jdksJDKs that Gradle downloaded for toolchainsOnly downloaded again if your build has a toolchain resolver configured

Keep gradle.properties and init.d in the same folder. They are your settings, not cache, and gradle.properties often holds repository credentials or signing settings.

Each project also has its own .gradle folder and a build folder next to build.gradle or build.gradle.kts. Those are covered further down.

Measure it first

This only reads sizes:

GH="${GRADLE_USER_HOME:-$HOME/.gradle}"
du -sh "$GH"/caches/* "$GH"/wrapper/dists/* "$GH"/daemon "$GH"/jdks 2>/dev/null | sort -h

The output tells you where to start. If one old version under caches/ or wrapper/dists/ is large, you can remove just that one. If modules-2 is the large one, decide whether you can afford to download your dependencies again.

Let Gradle clean it automatically

Gradle already deletes unused cache entries on its own. By default it checks at most once every 24 hours, in the background when a daemon stops:

  • dependencies from a remote repository: removed after 30 days without use
  • entries Gradle created itself, such as transforms: after 7 days
  • local build cache entries: after 7 days
  • caches and wrapper distributions of Gradle versions you no longer run: after 30 days
  • daemon logs: after 14 days

If the folder keeps growing anyway, shorter retention is often a better fix than deleting everything by hand. On Gradle 8.0 or newer, put an init script in the init.d folder of your Gradle User Home, for example ~/.gradle/init.d/cache-settings.init.gradle.kts:

beforeSettings {
    caches {
        buildCache.setRemoveUnusedEntriesAfterDays(3)
        downloadedResources.setRemoveUnusedEntriesAfterDays(14)
    }
}

The setting applies to every build that uses that Gradle User Home. Older Gradle versions sharing the same folder keep their fixed periods. The Gradle docs show how to guard the script with a version check if you still run builds older than 8.0.

Stop the Gradle daemons before deleting

A running daemon holds locks in caches/. Stop it first. Run this in each project you build:

./gradlew --stop

--stop only stops daemons of the same Gradle version as that project. If you have projects on several versions, list all daemons regardless of version:

jps | grep GradleDaemon
pgrep -f GradleDaemon

jps comes with the JDK. Stop any daemon that is left with ./gradlew --stop from a project on that version, or end the process. Quit Android Studio or IntelliJ IDEA too, because they start their own daemons. Stopping can take a few seconds, so check again before you delete.

Clear one part of the cache

Each of these is independent. Use the shortcut from above:

GH="${GRADLE_USER_HOME:-$HOME/.gradle}"

Clear the local build cache only. Builds rerun tasks they would have loaded from the cache, and your dependencies stay:

rm -rf "$GH/caches/build-cache-1"

Remove the caches and the wrapper distribution of a Gradle version you no longer use. Check gradle/wrapper/gradle-wrapper.properties in your projects first, so you do not remove a version an active project still uses:

ls "$GH/caches" "$GH/wrapper/dists"
rm -rf "$GH/caches/8.5" "$GH/wrapper/dists/gradle-8.5-bin"

Replace 8.5 with the version you want to remove. Distribution folders end in -bin or -all depending on the wrapper setting.

Remove a JDK that Gradle downloaded for a toolchain:

ls "$GH/jdks"

Delete the one you no longer need, then stop the daemons, because a running daemon may still remember the old toolchain path.

Clear the whole Gradle cache

If you want all of it back, delete the caches folder after the daemons are stopped:

rm -rf "${GRADLE_USER_HOME:-$HOME/.gradle}/caches"

Your next build recreates the folder and downloads every dependency it needs again. That needs a network connection and access to every repository your builds use, including private ones. If you work offline, keep modules-2: with it gone, a build with --offline fails because Gradle cannot resolve the dependencies.

Do not delete the whole ~/.gradle folder unless you mean to. That also removes gradle.properties, your init scripts and the downloaded wrapper distributions.

If a dependency looks broken

Deleting the cache is not the first fix for a bad or outdated dependency. Try a refresh first:

./gradlew build --refresh-dependencies

Gradle then ignores its cached resolution results and checks the repositories again. It compares checksums and does not download files that are unchanged, so it is much cheaper than wiping modules-2.

Project folders: build and .gradle

./gradlew clean deletes the project's build folder and nothing else. The project's .gradle folder holds incremental build state and the configuration cache for that project. Gradle removes old version folders in it after 7 days without use. You can delete both folders in a project you are not working on; the next build is a full build. Close the IDE for that project first.

The easier option: DevCleaner

DevCleaner is an app for macOS and Linux that measures developer caches and shows the size of each item before you clean anything.

On macOS, the Gradle rows sit in the Android Studio section and appear whenever ~/.gradle exists, including when Android Studio is not installed. DevCleaner shows Gradle Caches, Gradle Daemon Logs and old wrapper distributions, with sizes before you clean. Gradle Caches covers local caches such as build-cache-1, transforms-* and jars-*. It is Safe and part of Quick Clean. modules-2 and metadata-* are a separate Warning row, off by default and not part of Quick Clean, because deleting them breaks offline builds until the dependencies are fetched again. Old Gradle Wrapper Dists keeps the newest distribution and offers the older ones as Warning, off by default.

Project build, .gradle and .cxx folders next to a Gradle build file show up under Project Artifacts. They are never selected for you, and DevCleaner skips a folder while a Gradle or Java process is running in that project.

On Linux, DevCleaner lists Gradle Caches, Gradle Daemon Logs, Gradle Wrapper Distributions and the Gradle native cache as separate rows, and selects none of them by default.

DevCleaner reads ~/.gradle only. If you set GRADLE_USER_HOME to another folder, use the commands above.

The free version scans every supported tool and cleans built-in Safe categories. Pro is $19.99 a year or $59 lifetime and covers up to 3 devices (Mac or Linux). A 14-day Pro trial does not charge a card and does not start a subscription.

FAQ

Is it safe to delete ~/.gradle/caches?
Yes, if no Gradle daemon is running and you can download your dependencies again. Gradle rebuilds the folder on the next build. The first build afterwards takes longer and needs network access.
Does ./gradlew clean clear the Gradle cache?
No. It deletes the build folder of the current project. The shared caches in ~/.gradle stay. To skip the build cache for one run, use ./gradlew build --no-build-cache.
Can I delete ~/.gradle/wrapper/dists?
Yes. These are full Gradle downloads. Each project's wrapper downloads its version again the next time you run ./gradlew. Gradle also removes distributions on its own once no project has used them for 30 days.
Will clearing the Gradle cache fix Android Studio sync errors?
Sometimes. Try --refresh-dependencies or File, then Sync Project with Gradle Files first. If the cache is corrupted, stop the daemons, quit Android Studio and delete caches. For Android SDK and emulator storage, see the Android Studio guide.
Where is the Gradle cache on Windows?
C:\Users\<USERNAME>\.gradle, unless GRADLE_USER_HOME is set. The folder layout is the same.

Scan it with DevCleaner

DevCleaner shows the Gradle cache folders and their sizes before you clean.

Download DevCleaner ↓

References and scope

Checked against Gradle 9.8.2, the current release on November 3, 2026, on Linux with JDK 21. Paths are the same on macOS. DevCleaner details are for macOS 1.17.1 and Linux 1.1.1.

Featured on TryMacApps Featured on UsefulShelf Featured on Formac Listed on MacTools Pro Fazier badge