What is ~/.m2/repository on Mac? Is it safe to delete?
You can delete ~/.m2/repository without breaking Maven, but it costs time. Every project downloads its dependencies and plugins again on the next build, and anything you installed there yourself has to be built again.
Where it is
~/.m2/repositoryWhat it is
Maven, the build tool used by many Java projects, keeps a local repository in ~/.m2/repository. Every library and plugin a build needs is downloaded once and stored there, so later builds can work without fetching it again. Gradle and other JVM tools can read from it too.
It grows with every dependency version your projects have ever used, and Maven never removes old versions by itself. The folder also holds artifacts you built with mvn install, which did not come from the internet.
Next to it, ~/.m2/settings.xml holds your Maven settings, which can include mirrors and repository credentials. It is not part of the repository and should be kept.
How big it gets
Often several GB on a Mac used for Java development, and more if you work on many projects or with large frameworks.
How to clear it by hand
- Run the command below to see how large the repository is. It only reads the size.
- Close your IDE and stop any running builds.
- In Finder, choose Go > Go to Folder, enter ~/.m2 and move the repository folder to the Trash. Leave settings.xml and settings-security.xml where they are.
- Build a project once while you have a good connection, since everything is downloaded again.
du -sh ~/.m2/repositoryWhat happens afterwards
The first build of each project is slower and needs the network. Artifacts you installed locally with mvn install are gone until you build those projects again. Your source code and Maven settings are not touched.
How Diskzy handles it
Diskzy shows ~/.m2 and its size on the disk map, counted with developer data under System Data, so you can see whether the repository is worth clearing.
Related guides
See where your Mac's space went
Diskzy maps your disk, explains System Data and clears what's safe. Free for 72 hours, then $9 once for 2 Macs.
Try Diskzy for free