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

Is it safe to delete? · Package caches · Updated 21 November 2026. By Mohit Nippanikar, who makes SiftMac.

## The short answer

- **Mostly.** Nearly everything in it is libraries and plugins Maven downloaded, and those come back on the next build. The exceptions are your own modules put there by `mvn install`, and the settings file next to it.
- **What it costs you:** the next build downloads every dependency and plugin again, and projects that use your own locally installed modules need those rebuilt first.
- **Does it come back?** Yes, as you build.
- SiftMac’s verdict: Rebuilds

## 1. What the local repository is

Maven’s docs describe the local repository as a directory on your computer that caches remote downloads and contains temporary build artifacts you haven’t released yet. Every Maven project on your Mac, and IDEs that build them, share it.

- **Dependencies and plugins** Maven downloaded, in folders by group, artifact and version, such as `org/apache/maven/plugins/…`.
- **Your own artifacts.** `mvn install` copies a project’s build output here so other local projects can use it. Those aren’t on any server, so removing them means building those projects again.
- **Old versions** of everything. When a project moves to a new version of a library, the old one stays.

## 2. Where it is

```
~/.m2/repository
~/.m2/settings.xml
~/.m2/wrapper
```

`~/.m2/repository` is the default local repository; a `<localRepository>` entry in `settings.xml` can move it. `settings.xml` holds your user settings, including the repository usernames and passwords Maven says belong there rather than in a `pom.xml`. `~/.m2/wrapper` is where the Maven Wrapper (`./mvnw`) installs the Maven versions your projects ask for.

## 3. How big it gets

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

The second command shows the largest top-level groups, so you can see which libraries and plugin families take the most.

## 4. How to clear it

Maven’s docs say you shouldn’t need to do anything with the local repository regularly, except clean it out when you’re short on disk space, or erase it completely if you’re willing to download everything again. Choose how far to go:

- **One project’s dependencies:** run `mvn dependency:purge-local-repository` in that project. It removes them and, by default, resolves them again; add `-DreResolve=false` to only remove them.
- **Snapshots only:** add `-DsnapshotsOnly=true` to purge just the SNAPSHOT versions.
- **Everything:** quit your IDE, make sure no build is running, and empty the folder.

```
mvn dependency:purge-local-repository -DreResolve=false
rm -rf ~/.m2/repository/*
```

Before emptying it, note which of your own modules you installed locally (look for your own group ID in the folder), so you know which projects need `mvn install` again. Keep `settings.xml`.

## 5. What happens afterwards

- The next build of each project downloads its dependencies and every plugin it runs, from the ones behind `clean` and `compile` onwards, so it’s slow and needs the network.
- Offline builds (`mvn -o`) fail until those downloads have happened.
- Projects that depend on your own locally installed modules can’t resolve them until you run `mvn install` in those modules again.
- Your projects’ sources and `pom.xml` files aren’t touched.

## 6. Build output in projects

Each Maven project also keeps its build output in its own folder, usually `target`. `mvn clean` runs the Clean Plugin, which deletes the project’s build directories, and the next build makes them again. Gradle projects keep a similar shared cache in [`~/.gradle`](https://siftmac.com/safe-to-delete/gradle-caches).

## Questions

### Will deleting ~/.m2 delete my Maven settings?

Deleting the whole `~/.m2` would: `settings.xml` lives there, with mirrors, profiles and server credentials. Clear `~/.m2/repository` instead and the settings stay.

### Why is one of my libraries missing after I cleared the repository?

If it’s one of your own modules, it only ever existed on your Mac, put there by `mvn install`. Build and install that module again; libraries from a remote repository download by themselves.

### Can I delete only old versions?

Yes. Version folders a project no longer uses can go one at a time, at `~/.m2/repository/<group path>/<artifact>/<version>`; if a build still needs one, Maven downloads it again.

### Does mvn clean empty ~/.m2?

No. `mvn clean` only deletes one project’s build output. The local repository is shared by all your projects and has no clean command of its own.

## How SiftMac handles it

SiftMac doesn’t clear `~/.m2`. Its space map shows the repository’s size and notes that its libraries download again on the next build. It also doesn’t list Maven projects’ `target` folders: its `target` rule is for Rust projects with a `Cargo.toml`.

Download: https://siftmac.com/SiftMac.dmg (scanning is free, and so is the first 2 GB of cleaning).

## Sources

- [Maven: Introduction to repositories](https://maven.apache.org/guides/introduction/introduction-to-repositories.html)
- [Maven: Settings reference (localRepository, settings.xml)](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)
- [Maven Wrapper](https://maven.apache.org/wrapper/)
- [Maven Clean Plugin](https://maven.apache.org/plugins/maven-clean-plugin/)

## Related

- [Is it safe to delete Gradle’s caches in ~/.gradle?](https://siftmac.com/safe-to-delete/gradle-caches)
- [Is it safe to delete ~/Library/Caches/JetBrains?](https://siftmac.com/safe-to-delete/jetbrains-caches)
- [Xcode DerivedData, node_modules and Docker: what’s safe to delete on a developer’s Mac](https://siftmac.com/guides/developer-files-on-mac)
- [What fills a developer’s Mac, and what’s safe to delete](https://siftmac.com/for/developers)

Canonical: https://siftmac.com/safe-to-delete/maven-repository
