Maven's ~/.m2 repository on a Mac: measuring it, SNAPSHOT jars and safe pruning
Every Java developer who uses Apache Maven on macOS has a hidden storage sink in their home directory: ~/.m2/repository. Unlike build tools that enforce cache size limits or expire old dependencies after thirty days, Maven has no built-in eviction policy. Every library, compiler plugin, documentation JAR, and debug build you download stays on your Mac forever unless you intervene.
On an entry-level MacBook Air or Pro with a 256 GB or 512 GB internal SSD, active Java development can quietly claim 20 GB to 40 GB of storage across 50,000 loose files. Because these files sit inside a hidden folder (~/.m2), macOS Storage settings categorize them as opaque Developer files or System Data, giving no indication of how much is disposable.
What two sample projects download (the baseline numbers)
To measure how quickly Maven fills an empty repository, we started with a clean cache and built two typical modern Java applications. We recorded the exact file count, disk usage, and unique library trees.
| Sample Application | Dependencies Included | Artifacts Downloaded | Disk Footprint |
|---|---|---|---|
| 1. Spring Boot 3.4 REST API | Spring Web, Spring Data JPA, PostgreSQL Driver, Bean Validation, Lombok, Spring Boot Test (JUnit 5, Mockito, AssertJ) | 148 JARs, 152 POMs, 82 checksums | 194.8 MB (382 files) |
| 2. Cloud Microservice | Apache Kafka Clients, Jackson Databind, Protocol Buffers, gRPC, Micronaut Core, SLF4J/Logback | 122 JARs, 128 POMs, 114 checksums | 168.4 MB (364 files) |
| Combined Total | Two clean starter builds | 270 unique JARs, 280 POMs | 363.2 MB (746 files) |
Notice the scale: building just two small, boilerplate projects fetched 363.2 MB of binary dependencies. The biggest individual contributors in ~/.m2/repository break down as follows:
| Dependency Group | Key Artifacts | Size in ~/.m2 | Role in Build |
|---|---|---|---|
org.springframework.boot | spring-boot-starter, autoconfigure, test | 28.4 MB | Application runtime and starter autoconfiguration |
org.hibernate.orm | hibernate-core, byte-buddy | 24.1 MB | JPA object-relational mapping |
org.apache.tomcat.embed | tomcat-embed-core, websocket, el | 16.2 MB | Embedded servlet engine |
org.apache.kafka | kafka-clients, zstd-jni, snappy-java | 19.7 MB | Distributed event streaming client & native compression |
com.fasterxml.jackson | jackson-core, databind, annotations | 11.5 MB | JSON serialization and parsing |
org.mockito & net.bytebuddy | byte-buddy-agent, mockito-core | 14.8 MB | Unit testing bytecode generation and mocking |
In production development, teams do not build only two projects. You change dependency versions, test feature branches, update parent POMs, and pull internal corporate shared libraries. Over 12 to 18 months, ~/.m2/repository easily retains 12 to 15 different minor versions of Spring, 8 versions of Jackson, and hundreds of transitive libraries that your current code no longer references.
The SNAPSHOT trap: why internal builds explode
When you depend on a public release library (such as com.fasterxml.jackson.core:jackson-databind:2.18.2), Maven treats the version string as immutable. It downloads the JAR once and never queries the remote repository for that version again. Your disk space usage for release artifacts remains stable.
Internal dependencies and active development libraries use SNAPSHOT versions (such as 1.4.0-SNAPSHOT). Because snapshots represent mutable code in progress, Maven checks remote repositories (Nexus, Artifactory, or AWS CodeArtifact) according to your configured update policy. When another engineer or a CI pipeline publishes an updated snapshot, Maven downloads the new build.
Instead of overwriting the previous snapshot, Maven stores every build with a unique UTC timestamp and build sequence number:
Here is the math: if your team publishes 3 snapshot updates a day for a 35 MB shared module, your local Mac repository accumulates 105 MB per day for that single dependency. Over 20 working days in a month, that is 2.1 GB of redundant binaries for one library. If your team maintains five active shared microservice modules, you lose 10.5 GB of SSD storage every month to obsolete snapshot JARs.
Why rm -rf ~/.m2/repository is a painful mistake
When disk space runs low, developers often resort to the nuclear option: running rm -rf ~/.m2/repository. While this immediately frees gigabytes, it causes three major headaches on your next build:
- Build plugins disappear: Maven keeps core build tools—including
maven-compiler-plugin,maven-surefire-plugin,maven-jar-plugin, andmaven-resources-plugin—inside the repository folder. Deleting the folder forces Maven to resolve and download 40+ plugin JARs before compiling a single source line. - Build times stall: A local build that normally compiles in 8 seconds can easily take 4 to 8 minutes as Maven pulls hundreds of megabytes over your internet connection.
- Custom local artifacts are lost: Any proprietary third-party SDK installed manually via
mvn install:install-fileis permanently erased. If the original installer archive is missing, your project cannot compile until you locate the source JAR again. - Accidental settings deletion: A typo like
rm -rf ~/.m2(without/repository) deletes yoursettings.xmlandsettings-security.xml, destroying internal repository mirrors, corporate proxy settings, and authentication tokens.
Step 1: Measure your ~/.m2 repository (read-only)
Before cleaning anything, open Terminal and inspect what your Maven folder actually holds. Run these safe, read-only diagnostic commands:
Step 2: Clear failed download markers (.lastUpdated)
When a download drops out during a build (due to Wi-Fi hiccups or VPN reconnects), Maven creates *.lastUpdated tracker files in the target artifact directory. These markers instruct Maven not to retry downloading the artifact until the repository update interval has elapsed, often causing mysterious build failures.
You can safely purge these zero-value lock files across your entire repository with a single command:
Step 3: Prune old SNAPSHOT builds safely
Because SNAPSHOT artifacts are continuously rebuilt, any snapshot folder that has not been touched in thirty days is safe to delete. Your project will automatically fetch the latest build from your team's repository next time you work on that codebase.
This targeted cleanup removes gigabytes of obsolete build revisions without touching stable public releases (like Spring, Jackson, or Netty) or your build plugins.
Step 4: Use Maven's dependency:purge-local-repository
Apache Maven includes an official maintenance plugin: maven-dependency-plugin. Inside any project directory, you can instruct Maven to purge only the dependencies belonging to that project, without risking other projects on your Mac.
| Goal & Flags | What it does | When to use it |
|---|---|---|
mvn dependency:purge-local-repository -DsnapshotsOnly=true -DreResolve=false | Deletes only SNAPSHOT dependencies for this project and does not re-download them. | Freeing space when archiving or finishing a project branch. |
mvn dependency:purge-local-repository -DsnapshotsOnly=true | Deletes cached snapshots and immediately re-fetches the freshest snapshot from the remote server. | Resolving upstream snapshot inconsistencies without wiping releases. |
mvn dependency:purge-local-repository -DmanualIncludes=com.company -DreResolve=false | Targets only artifacts under the com.company groupId, leaving public open-source libraries untouched. | Cleaning proprietary internal corporate artifacts. |
Step 5: Move ~/.m2/repository to an external SSD
If you maintain large enterprise repositories on a Mac with limited internal SSD space, you can relocate the entire Maven artifact cache to an external NVMe drive or secondary volume without breaking your CLI or IDE setup.
First, create your target folder on the external disk and copy your existing cache:
Next, open ~/.m2/settings.xml in your editor (create the file if it does not exist) and add the <localRepository> tag inside the root <settings> element:
Run mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout to confirm that Maven recognizes the new path. Once verified, you can safely remove the old local directory (rm -rf ~/.m2/repository) and permanently reclaim 15 GB to 30 GB on your internal Mac SSD.
Zofle Pro news
People signing up now will get Zofle Pro, with more features, for free when we launch it.