Maven .m2 Repository on Mac: Safe to Delete?
High riskPackage managers & build toolsUpdated
- Location
~/.m2/repository
- Risk level
- High riskLarge stores — whole dependency repositories or downloaded AI models — that take a long time to get back. Listed, never pre-selected.
- Selected by default
- No — you choose whether to include it
- What Freshist does
- Moves the selected items to the Trash, so you can undo. Nothing is deleted outright.
- In the app
- Clean → Maven Repository — “Java dependency repository — LARGE; Maven re-downloads every dependency on next build.”
From Freshist's own cleaning rules — the same catalog the app uses.
What the local repository is
Maven never builds against files on a remote server directly. Before a build, it downloads each dependency (JARs, POMs, checksums) and every plugin it needs into the local repository, which is ~/.m2/repository unless settings.xml sets localRepository somewhere else. Folders follow the artifact coordinates, so org/apache/commons/commons-lang3/3.14.0/ holds exactly that version.
Two kinds of content end up here:
- Downloaded artifacts from Maven Central, company mirrors and other remote repositories.
- Locally installed artifacts, which land here when you run
mvn installon your own modules, often as-SNAPSHOTversions.
Why it gets so large
Maven keeps every version it has ever resolved and never removes old ones. Each project upgrade adds a new version next to the old, plugins pull in their own dependency trees, and snapshot builds can store many timestamped copies. Java developers with a few years of history often find several gigabytes here.
What you lose if you delete it
| Content | After deletion |
|---|---|
| Artifacts from Maven Central or a reachable mirror | Downloaded again on the next build |
| Maven plugins | Downloaded again; the first build is noticeably slower |
Your own modules installed with mvn install | Gone until you rebuild and install them |
| Artifacts from retired or VPN-only repositories | Builds fail until you can reach that repository again |
~/.m2/settings.xml and credentials | Untouched, as long as you remove only repository |
Offline builds (mvn -o) stop working until the repository is filled again.
Measure it first
du -sh ~/.m2/repository
du -sh ~/.m2/repository/* | sort -h | tail -20 # largest groupIds
mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout
The last command prints the repository path Maven is really using, which matters if a settings.xml overrides the default.
Clean it with Maven
The Maven Dependency Plugin has a goal built for this:
mvn dependency:purge-local-repository
Run inside a project, it removes that project's dependencies from the local repository and then re-resolves them, so you end up with a fresh copy. The plugin's own documentation suggests turning off re-resolution when you run it from the command line, with -DreResolve=false. To target specific artifacts, pass -DmanualInclude=groupId:artifactId.
For a full reset, quit your IDE so it isn't indexing the folder, then move ~/.m2/repository to the Trash. Rebuild your own modules with mvn install before building projects that depend on them.
Cases where a wipe hurts
Keep it if you work offline, depend on an internal repository that is only reachable on a company network, or have local snapshot artifacts other projects need. Targeted purging is safer than a wipe in all of those cases. The IDE side of Java development has its own cache, covered in the JetBrains cache guide, and the developer caches overview puts Maven next to the other build tools.
Sources
Frequently asked questions
Does deleting ~/.m2/repository remove my Maven settings?
No. Your settings.xml, mirrors and server credentials live in ~/.m2/settings.xml, one level above the repository folder. Remove only the repository folder, never all of ~/.m2.
Do Gradle builds use ~/.m2/repository too?
Only if a Gradle build declares mavenLocal(). Gradle normally keeps its own cache in ~/.gradle/caches, so clearing the Maven repository rarely affects Gradle projects.
How do I clear the repository for just one project?
Run mvn dependency:purge-local-repository inside that project. It deletes that project's dependencies from the local repository and, by default, downloads them again straight away.