Complete Guide to Cleaning Up Gradle and Flutter Caches on Windows

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

If you develop Android or Flutter apps on Windows, chances are your C:\Users\<username>\.gradle folder has quietly grown to consume tens of gigabytes. Itโ€™s normal โ€” Gradle stores downloaded dependencies, compiled caches, and temporary build files there.
But after months (or years) of active development, you can reclaim 10โ€“35 GB of space safely without breaking your setup.

This tutorial explains, step-by-step, how to safely clean up Gradle and Flutter caches, understand what each folder does, and use simple scripts to automate it.


Locating the .gradle Directory

On Windows, the Gradle home directory lives here:

C:\Users\<your-username>\.gradle

In your case:

C:\Users\ashwa\.gradle

When you open it, youโ€™ll see folders such as:

.tmp
android
caches
daemon
jdks
kotlin-profile
native
notifications
workers
wrapper
android.lock

Each of these has a purpose โ€” some can be safely deleted, others should remain.


Understanding Each Folder (and Whatโ€™s Safe to Delete)

FolderPurposeCan I Delete It?Notes
.tmpTemporary Gradle filesโœ… SafeWill be recreated automatically
cachesStores old build caches, plugin downloads, dependency jarsโœ… SafeFrees 10โ€“20 GB
daemonBackground Gradle processesโœ… SafeStop Gradle first (gradle --stop)
nativeNative build artifactsโœ… SafeRegenerated when needed
workersMetadata about worker threadsโœ… SafeRecreated automatically
jdksGradle-downloaded JDKsโš ๏ธ Partially safeKeep one version currently in use
androidAndroid build system filesโš ๏ธ KeepNeeded if you build Android apps
wrapperGradle wrapper distributionsโŒ KeepUsed for project version matching
notificationsBuild-related notificationsโœ… SafeRecreated as needed
android.lockLock fileโœ… SafeUsually 0 KB; harmless to delete

Cleaning Gradle Caches Safely

Before deleting anything, close Android Studio, VS Code, and all Flutter terminals to prevent Gradle from running in the background.

Option A โ€” Command-Line Cleanup (Recommended)

Open PowerShell or Command Prompt:

# Stop all Gradle daemons
gradle --stop

# Remove unnecessary Gradle folders
rd /s /q "%USERPROFILE%\.gradle\caches"
rd /s /q "%USERPROFILE%\.gradle\daemon"
rd /s /q "%USERPROFILE%\.gradle\native"
rd /s /q "%USERPROFILE%\.gradle\workers"
rd /s /q "%USERPROFILE%\.gradle\.tmp"

Gradle will rebuild everything it needs automatically the next time you build a project.


Option B โ€” Manual Deletion

If you prefer a graphical approach:

  1. Open C:\Users\ashwa\.gradle in File Explorer.
  2. Select and delete the folders: caches daemon native workers .tmp
  3. Empty the Recycle Bin.

Thatโ€™s it โ€” your next Gradle or Flutter build will recreate the necessary files.


How Gradle and Flutter Rebuild Caches Automatically

When you delete .gradle\caches and .gradle\.tmp, Gradle doesnโ€™t lose critical project data โ€” it simply removes downloaded and compiled artifacts.
At your next build or flutter run, Gradle:

  • Checks which dependencies are needed.
  • Re-downloads them from Maven or Google repositories.
  • Re-compiles and caches them locally again.

This first build after cleanup might take a bit longer (since itโ€™s downloading fresh artifacts), but everything remains 100 % functional.


Cleaning Flutter-Specific Caches

Flutter maintains its own package and build cache separately.
To clear it:

flutter clean
flutter pub cache repair

If you want a deeper cleanup:

rd /s /q "%APPDATA%\Pub\Cache\git"
rd /s /q "%APPDATA%\Pub\Cache\hosted"

These commands remove old package versions from your Dart/Flutter cache.


Managing Old Gradle Versions in the Wrapper

You may also notice inside:

C:\Users\ashwa\.gradle\wrapper\dists

that there are many folders like:

gradle-5.4.1-all
gradle-6.8-all
gradle-7.6.3-bin
gradle-8.10-all
gradle-8.12-all
...

Each folder corresponds to a Gradle version downloaded by your projectsโ€™ wrappers.
Every project includes a file:

<project>\gradle\wrapper\gradle-wrapper.properties

Inside, youโ€™ll find a line like:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip

This tells you which version your project uses.

If all your current projects use Gradle 8.x, you can safely delete older 5.x, 6.x, 7.x folders. Gradle will re-download any missing version automatically if a project requires it later.


PowerShell Script to Automate Cleanup

You can create a script cleanup-gradle.ps1 that performs the cleanup automatically:

Write-Host "Stopping Gradle daemons..."
gradle --stop 2>$null

$paths = @(
  "$env:USERPROFILE\.gradle\caches",
  "$env:USERPROFILE\.gradle\daemon",
  "$env:USERPROFILE\.gradle\native",
  "$env:USERPROFILE\.gradle\workers",
  "$env:USERPROFILE\.gradle\.tmp"
)

foreach ($p in $paths) {
  if (Test-Path $p) {
    Write-Host "Removing $p"
    Remove-Item -Recurse -Force $p
  }
}

Write-Host "Gradle cleanup complete โœ…"

To run it:

  1. Save the script as cleanup-gradle.ps1.
  2. Right-click โ†’ Run with PowerShell.
  3. Wait for it to finish.

This script only removes safe folders โ€” you keep your Android, wrapper, and JDK files intact.


Cleaning Up Old Gradle Distributions Automatically

To go further, hereโ€™s an advanced PowerShell snippet that deletes all old Gradle versions (below 8.x) or unused ones automatically:

# Adjust this to where your projects are located
$Root = "C:\Users\ashwa"

gradle --stop 2>$null

# Detect versions actually in use by your projects
$wrappers = Get-ChildItem -Path $Root -Filter gradle-wrapper.properties -Recurse -ErrorAction SilentlyContinue
$inUse = [System.Collections.Generic.HashSet[string]]::new()
$wrappers | ForEach-Object {
  $text = Get-Content $_.FullName -Raw
  if ($text -match 'gradle-([0-9]+\.[0-9]+(\.[0-9]+)?)\-(all|bin)\.zip') {
    $null = $inUse.Add($Matches[1])
  }
}

Write-Host "Gradle versions referenced by your projects:" ($inUse | Sort-Object)

$dists = Join-Path $env:USERPROFILE ".gradle\wrapper\dists"
$toDelete = Get-ChildItem $dists -Directory | Where-Object {
  if ($_.Name -match 'gradle-([0-9]+)\.([0-9]+)(\.[0-9]+)?-') {
    $major = [int]$Matches[1]
    $ver = "$($Matches[1]).$($Matches[2])"
    -not $inUse.Contains($ver) -or $major -lt 8
  }
}

# Preview first
$toDelete | Select-Object -ExpandProperty FullName
# Remove -WhatIf to actually delete
$toDelete | ForEach-Object { Remove-Item $_.FullName -Recurse -Force -WhatIf }

Run once with -WhatIf to preview, then again without it to delete for real.


Extra Space-Saving Tips for Developers

To reclaim even more space:

ComponentTypical LocationSafe Cleanup Action
Android SDK%LOCALAPPDATA%\Android\SdkDelete old system images & unused build-tools
Temp files%LOCALAPPDATA%\TempUse Disk Cleanup or manually delete
npm cache%APPDATA%\npm-cachenpm cache clean --force
VS Code cache%APPDATA%\Code\CacheSafe to delete
Docker imagesif you use Dockerdocker system prune -a

Expected Space Savings

Cleanup TypeApprox. Space Recovered
.gradle\caches10โ€“20 GB
Flutter pub cache1โ€“5 GB
Android SDK cleanup5โ€“10 GB
Windows temp & others2โ€“5 GB

Total potential reclaimed: 20โ€“35 GB.


After Cleanup โ€” What to Expect

  • First Gradle or Flutter build will take longer since dependencies are re-downloaded.
  • After the first build, performance returns to normal.
  • All deleted folders will reappear as Gradle rebuilds whatโ€™s needed.
  • Youโ€™ll enjoy a lighter, cleaner development environment with plenty of disk space reclaimed.

Summary

Cleaning Gradle and Flutter caches is completely safe as long as you understand what each folder does.
You can always delete:

  • .gradle\caches
  • .gradle\.tmp
  • .gradle\daemon
  • .gradle\native
  • .gradle\workers
  • Old Gradle versions (5.x, 6.x, 7.x) under .gradle\wrapper\dists

Gradle and Flutter will automatically restore anything necessary.
Performing this maintenance once every few months is a great habit for keeping your Windows development machine healthy and responsive.

Leave a Reply

Your email address will not be published. Required fields are marked *

0
Would love your thoughts, please comment.x
()
x