Folder

Is ~/.m2/repository safe to delete on a Mac?

Mostly: ~/.m2/repository is a cache of remote downloads that Maven fetches again, but it also holds artifacts you built with mvn install and never published, and those are gone for good.

2 safe1 careful1 never

updated read 3 minfor Maven 3 and later on macOS

The short answer

  1. 01

    Careful. ~/.m2/repository is Maven's local repository. Downloaded artifacts come back; artifacts you only installed locally do not.

  2. 02

    Maven writes it when a build needs a dependency it does not have, and the install phase adds your own builds to it.

  3. 03

    You lose download time for everything, plus any mvn install output that exists nowhere else, such as a library another local project depends on.

  4. 04

    The command: mvn dependency:purge-local-repository inside a project clears that project's dependencies and re-resolves them. To clear everything, rm -rf ~/.m2/repository.

  5. 05

    Keep ~/.m2/settings.xml. It holds your Maven settings and often repository credentials.

See its real size on your Mac. Hoardless measures this folder and previews the delete.Download free trial

What is the ~/.m2/repository folder?

It is Maven's local repository. Maven's settings reference gives the default localRepository as ${user.home}/.m2/repository, which is ~/.m2/repository on a Mac. A localRepository entry in settings.xml moves it.

Maven's guide to repositories says the local repository caches remote downloads and contains temporary build artifacts that you have not yet released. That second part is why this folder is not a pure cache.

What writes it and why does it grow?

Two things write it.

  • Dependency downloads: any build that needs a dependency not in the local repository downloads it, and for a SNAPSHOT, downloads again when the remote one is newer.
  • mvn install: the Install Plugin adds your project's artifacts to the local repository during the install phase, so other local projects can use them.

Nothing is removed automatically. Every version of every artifact, and every snapshot you installed, stays until you delete it. IDEs that run Maven builds use the same folder unless configured otherwise.

How big does ~/.m2/repository get?

It depends on your projects and their dependency trees, so there is no normal size. Measure your own:

du -sh ~/.m2/repository

Prints the total. Removes nothing.

du -sh ~/.m2/repository/* | sort -h

Lists the top-level group folders (such as org and com) by size. Your own group id shows where your locally installed artifacts are.

Is it safe to delete ~/.m2/repository?

Maven's guide says you can erase it completely if you are willing to download everything again. The catch is what was never downloaded.

WhatVerdictWhat you lose
A project's dependencies, via purge-local-repositorySafeNothing; they are re-resolved right away by default.
Group folders of public librariesSafeDownloads. The next build fetches them again.
All of ~/.m2/repositoryCarefulEvery download, plus artifacts you installed with mvn install and never deployed. Rebuild those from source.
~/.m2/settings.xmlNeverYour mirrors, profiles and server credentials. It is config, not cache.

How do I clean ~/.m2/repository?

Per project, use Maven's own goal:

mvn dependency:purge-local-repository

Run inside a project. Per the Dependency Plugin docs, it removes the project's dependencies, transitive ones included, from the local repository and re-resolves them by default. Add -DreResolve=false to only remove them.

Everything at once, after checking you can rebuild anything you installed locally:

rm -rf ~/.m2/repository

Deletes the whole local repository permanently, without the Trash. Maven creates it again on the next build.

The manual way: in Finder, press Shift+Cmd+G, go to ~/.m2/repository, and drag the group folders you no longer need to the Trash, leaving your own group id until you have checked it.

What Hoardless does: its Gradle and Maven detector lists ~/.m2/repository at the Auto tier and moves the whole folder to the Trash after you review the plan, logged in the undo log so you can put it back. Its Explain panel says that anything you only installed locally with mvn install is lost. If you rely on that between projects, leave this folder out of the plan.

What comes back and when?

Downloads come back on the next build; each project resolves its dependencies from Maven Central or your configured repositories again.

Local-only artifacts do not. A project that depends on a library you installed with mvn install fails to build until you run mvn install in that library's project again.

See ~/.m2 next to your Gradle and IDE caches

Hoardless sizes ~/.m2/repository (Auto tier, moved to the Trash with an undo log) beside ~/.gradle/caches and JetBrains caches, and its Explain panel says what a delete loses before you approve the plan.

14-day full trial. macOS 14 or later.

Questions

Does Maven ever clean ~/.m2/repository by itself?

No. Maven's guide says you should not need to do anything with it except clean it out if you are short on disk space.

What is lost if I delete ~/.m2/repository?

Downloads from Maven Central and other remote repositories come back on the next build. Artifacts you put there with mvn install, and never deployed, must be rebuilt from their source projects.

Can I delete only one project's dependencies?

Yes. Run mvn dependency:purge-local-repository inside the project. It removes that project's dependencies, transitive ones included, and re-resolves them by default.

Is it safe to delete all of ~/.m2?

No. ~/.m2/settings.xml, if you have one, holds mirrors, profiles and server credentials. Delete only the repository folder.