Safe to Delete

Maven .m2 Repository Folder (~/.m2/repository)

Quick Answer: The .m2/repository folder caches downloaded Java dependencies for Maven and Gradle. Deleting it is safe and reclaims gigabytes of unused jar files.

Bottom Line: It is 100% safe to delete the .m2/repository folder. Maven will simply re-download any required dependencies from Maven Central the next time you build a Java or Spring Boot project.


What is the .m2 Repository Folder?

Located at ~/.m2/repository on macOS/Linux or %USERPROFILE%\.m2\repository on Windows, this folder is created by the Apache Maven build tool (and used by Gradle/IDE integrations).

When you build Java or Spring Boot applications, Maven downloads dependency JAR files into .m2/repository. Unlike some package managers that prune unused versions, Maven never deletes old dependency versions automatically. Over years of Java development, old library versions accumulate, bloating .m2/repository to 10 GB to 30 GB+.


Can You Delete .m2/repository?

✅ Yes, it is completely safe to delete.

  • No source code lost: Your Java files, pom.xml, and configuration files live in your project folders and are untouched.
  • Automatic recovery: Running mvn clean install or building in IntelliJ IDEA / Eclipse will re-download only the active dependencies needed for your project.

How to Safely Clean Up .m2 Repository

Method 1: Delete the Repository Directory (Complete Wipe)

To wipe all cached JARs across all past projects:

# macOS / Linux
rm -rf ~/.m2/repository

# Windows (Command Prompt)
rmdir /s /q %USERPROFILE%\.m2\repository

# Windows (PowerShell)
Remove-Item -Recurse -Force $env:USERPROFILE\.m2\repository

Method 2: Delete Old / Unused Dependencies via Maven Dependency Plugin

If you want to remove unused dependencies while keeping active ones:

mvn dependency:purge-local-repository

Discussion

Loading authentication...

Related in developer

The AI Engineer's Model Disk Cleanup Guide: Hugging Face, Ollama & PyTorch

The ultimate 1,200-word field guide for AI developers and local LLM hobbyists to reclaim 200GB+ from Ollama, Hugging Face, PyTorch, and vLLM model weights.

Safe to Delete

Android Studio System Index Cache (AndroidStudio Cache)

Android Studio caches Gradle project indexes, VFS caches, and compiler artifacts. Invalidate and clear is safe.

Safe to Delete

Ansible Automation Temp & Fact Cache (~/.ansible/tmp)

Ansible stores temporary playbook execution modules and target host fact JSON caches in ~/.ansible/tmp. Clearing Ansible tmp is safe.

Safe to Delete
Back to all files