Can I Delete the .m2 Folder on My Mac? (Maven Repository Cache)
~/.m2Yes, you can delete the .m2 folder. It is Maven's local repository cache, a pile of downloaded Java dependencies that Maven re-downloads automatically the next time you build. Nothing permanent lives in the cache itself. The one thing to check first: if ~/.m2 contains a settings.xml file, that is your configuration, not cache, so keep it and delete only the repository folder inside.
What it is
~/.m2 is the home of Maven's local repository. When a Maven build on your Mac needs a library it does not have yet, it downloads that dependency (the jar file plus its pom metadata) from Maven Central or your company's repository and stores it under ~/.m2/repository. Every later build reads from that folder instead of downloading again. The cache is shared by every Java project on the machine, so it accumulates a copy of every version of every dependency any project has ever pulled.
That is why it grows without limit. Update a project from one library version to the next and both versions stay on disk. Gradle builds can touch this folder too: Gradle keeps its own cache in ~/.gradle, but it reads from ~/.m2/repository when a build declares mavenLocal() and writes to it when you publish locally. On a Mac that has built Java projects for a while, ~/.m2 is often several gigabytes, and long-lived setups with many projects can reach 10 GB or more. Besides the repository folder, ~/.m2 may also hold settings.xml (repository mirrors, proxy settings, credentials for private repos) and occasionally toolchains.xml.
Is it safe to delete?
The repository folder is pure download cache, so deleting it breaks nothing. Your project source code, pom.xml files, and installed JDKs are untouched. The next mvn build (or Gradle build that needs mavenLocal) re-downloads exactly the dependencies that project uses. The cost is bandwidth and a slower first build, usually minutes on a normal connection. One real caveat: offline builds (mvn -o) will fail until the cache is repopulated, so do not clear it right before working somewhere without internet.
The care is in the aim, not the risk. If ~/.m2 contains settings.xml, deleting the whole folder wipes your mirrors, proxy setup, and private repository credentials, and those do not regenerate. Trash only ~/.m2/repository and you keep all of that. If there is no settings.xml, or you have never configured Maven by hand, the whole folder is fair game. Diskmack identifies ~/.m2 automatically and cleans the cache the safe way.
How to check its size
In Finder: In Finder, choose Go > Go to Folder (Shift-Command-G), type ~/.m2 and press Return. The folder is normally hidden, but Go to Folder opens it anyway. Select the repository folder inside and press Command-I to see its size.
In Terminal:
du -sh ~/.m2The tilde expands to your home folder, so this measures /Users/yourname/.m2.
How to clean it
- Quit anything that might be running a Java build: IntelliJ IDEA, Eclipse, VS Code, or a terminal with mvn or gradle active. You do not want the cache repopulating mid-delete.
- In Finder, choose Go > Go to Folder (Shift-Command-G) and enter ~/.m2.
- Look for settings.xml or toolchains.xml. If either exists, leave it where it is. Those files are configuration, not cache.
- Move the repository folder to the Trash. If ~/.m2 holds nothing but repository, you can remove the whole folder instead: open your home folder in Finder, press Command-Shift-Period to show hidden files, and drag .m2 to the Trash.
- Empty the Trash to actually reclaim the space.
- Run your next build normally. Maven re-downloads the dependencies that project needs and recreates the folder on its own.
Maven has no built-in command that clears the whole local repository. The dependency:purge-local-repository plugin goal exists, but it works one project at a time and re-downloads as it goes, so trashing ~/.m2/repository by hand is simpler and more predictable.
Will it come back?
Yes. The folder reappears the first time any Maven build runs, and it refills with whatever dependencies your active projects use. That first rebuild per project is slower because everything comes down from the network again. From there it grows the same way it did before: every new project and every dependency version bump adds files that never get removed automatically. If you build Java regularly, expect ~/.m2 to creep back toward its old size over months. Clearing it once or twice a year is a reasonable rhythm; if you have stopped doing Java work entirely, it stays gone.
Common questions
Will deleting .m2 break Maven or my projects?
No. Maven recreates ~/.m2/repository on the next build and re-downloads what the project declares in its pom.xml. Your source code and Maven itself are untouched. The only failure mode is building offline before the cache has been repopulated.
What is settings.xml and why should I keep it?
It is Maven's per-user configuration file, stored at ~/.m2/settings.xml. It can hold repository mirrors, proxy settings, and credentials for private company repositories. Unlike the cache, it does not regenerate. If you delete it, you may be unable to reach your company's internal packages until you recreate it. If the file does not exist, you have nothing to preserve.
I don't write Java. Why do I have a .m2 folder?
Some tool on your Mac ran a Maven or Gradle build at some point: a work project you cloned once, a tutorial you followed, or an IDE downloading dependencies for a sample project. If nothing on the machine builds Java anymore, delete the folder. It will not come back on its own.
Does Gradle use ~/.m2, and is Gradle's cache separate?
Gradle keeps its own dependency cache in ~/.gradle/caches, which is a separate (and often larger) folder. Gradle only reads ~/.m2/repository when a build lists mavenLocal() as a repository, and writes to it when you run publishToMavenLocal. Deleting ~/.m2 is still fine in that setup; anything a build needs gets re-fetched or re-published.
Related folders
- Can I Delete the .gradle Folder on My Mac? Yes, Here's How
- Can I Delete the .ivy2 Folder on My Mac? Yes, and Here's Why
- Clearing the Cargo Cache on Mac: Is ~/.cargo/registry Safe to Delete?
- Is It Safe to Delete the Go Module Cache (~/go/pkg/mod) on a Mac?
- Rustup toolchains taking up space on your Mac? What's safe to delete