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 installor 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
Related Guides
- Learn about deleting [Gradle cache folder].
- How to clean up node_modules folders.
- Check if you can delete pip cache.
Discussion
Loading authentication...