# Maven .m2 Repository on Mac: Safe to Delete?

> ~/.m2/repository is Maven's local repository of every JAR and plugin your builds used. It can be deleted, but anything you only built locally is lost.

- Updated: 2026-10-10
- URL: https://fresh.ist/caches/maven/

**TL;DR:** Mostly yes. ~/.m2/repository is a local copy of dependencies and plugins downloaded from Maven Central and other remote repositories, and Maven fetches them again on the next build. The catch: artifacts you published there yourself with mvn install, and anything from a repository you can no longer reach, will not come back on their own.

## Facts from the Freshist app

- Category in Clean: Maven Repository — "Java dependency repository — LARGE; Maven re-downloads every dependency on next build."
- Location: `~/.m2/repository`
- Risk level: High risk — Large stores — whole dependency repositories or downloaded AI models — that take a long time to get back. Listed, never pre-selected.
- Selected by default: no
- What Freshist does: Moves the selected items to the Trash, so you can undo. Nothing is deleted outright.

## 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 install` on your own modules, often as `-SNAPSHOT` versions.

## 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

```bash
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:

```bash
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](/caches/jetbrains/), and the [developer caches overview](/blog/developer-caches-mac/) puts Maven next to the other build tools.

## Sources

- [Apache Maven: Introduction to repositories](https://maven.apache.org/guides/introduction/introduction-to-repositories.html)
- [Apache Maven: Settings reference (localRepository)](https://maven.apache.org/settings.html)
- [Maven Dependency Plugin: dependency:purge-local-repository](https://maven.apache.org/plugins/maven-dependency-plugin/purge-local-repository-mojo.html)

## 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.

---

Canonical page: https://fresh.ist/caches/maven/
Official site: https://fresh.ist/ (fresh.ist only)
Generated: 2026-10-10
