The Forbidden Maven Cache: How to Break CI in 10 Ways
The .m2
cache is Maven’s silent guardian—until it turns into your worst enemy. A corrupted cache can derail builds, waste hours of debugging, and even break CI pipelines in spectacular ways. Here’s how to accidentally (or intentionally) destroy your Maven cache—and how to recover from it.
1. The Nuclear Option: -U
(Force Update Snapshots)
What it does: Forces Maven to redownload every single dependency, ignoring the local cache.
How it breaks CI:
- Slows builds to a crawl by refetching all artifacts.
- Hits repository servers unnecessarily, risking rate limits.
mvn clean install -U # Say goodbye to cache optimizations
When to use it: Only when you really suspect corrupted snapshots.
2. --fail-never
(The “Ignore All Errors” Mode)
What it does: Makes Maven proceed even if dependencies fail to download.
How it breaks CI:
- Lets builds pass with missing/incomplete dependencies.
- Creates hidden tech debt when artifacts silently fail to resolve.
mvn install --fail-never # Who needs dependencies anyway?
When to use it: Never. (Seriously.)
3. -rf
(Resume From a Broken Module)
What it does: Skips previously built modules, even if they’re corrupted.
How it breaks CI:
- May produce inconsistent builds due to partial compilation.
- Masks real errors by pretending everything is fine.
mvn install -rf :core-module # Because who needs reproducibility?
When to use it: Only for local debugging—never in CI.
4. Manual .m2
Deletion (The Sledgehammer Approach)
What it does: Deletes the entire Maven cache.
How it breaks CI:
- Forces redownloading all dependencies, wasting time.
- Can trigger repository bans (e.g., Maven Central rate limits).
rm -rf ~/.m2/repository # Embrace chaos
When to use it: When you’ve exhausted all other options.
5. Using -Dmaven.repo.local
(The Rogue Cache)
What it does: Redirects Maven to a custom cache location.
How it breaks CI:
- Creates inconsistent cache states across builds.
- May lead to unreproducible builds.
mvn install -Dmaven.repo.local=/tmp/random-cache # Because predictability is overrated
When to use it: For isolated testing—never in shared environments.
6. Parallel Builds + Corrupt Cache (-T
Flag)
What it does: Runs Maven in parallel, increasing the chance of cache corruption.
How it breaks CI:
- Thread race conditions can corrupt downloaded artifacts.
- Hard-to-reproduce “flaky build” issues.
mvn install -T 4 # May the odds be ever in your favor
When to use it: Only with stable, well-tested builds.
7. Mixing -o
(Offline Mode) with a Broken Cache
What it does: Forces Maven to work offline, even if the cache is incomplete.
How it breaks CI:
- Fails with cryptic errors when dependencies are missing.
- Encourages “it works on my machine” syndrome.
mvn install -o # Because the internet is just a fad
When to use it: Only if you 100% trust your cache.
8. dependency:purge-local-repository
(The Silent Killer)
What it does: Deletes dependencies from .m2
without warning.
How it breaks CI:
- Leaves builds in an inconsistent state.
- Forces unnecessary re-downloads.
mvn dependency:purge-local-repository # Surprise! Your cache is gone.
When to use it: Rarely—prefer -U
instead.
9. Ignoring checksum
Warnings
What it does: Lets corrupted artifacts slip through.
How it breaks CI:
- Allows broken JARs into the build.
- Causes mysterious runtime failures.
[WARNING] Checksum validation failed, but proceeding anyway...
When to use it: Never. Fix the root issue instead.
10. Using Snapshots in CI (The Time Bomb)
What it does: Relies on volatile -SNAPSHOT
versions.
How it breaks CI:
- Makes builds non-reproducible.
- Can suddenly break if a snapshot updates mid-build.
<dependency> <groupId>com.example</groupId> <artifactId>unstable-lib</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
When to use it: Only in local development, never in CI.
How to Recover from Cache Disasters
- Clean & rebuild:
mvn clean install -U
2. Delete corrupt artifacts manually:
rm -rf ~/.m2/repository/problematic/group
3. Use dependency:resolve
to verify:
mvn dependency:resolve
Final Verdict: Tread Carefully
The .m2
cache is powerful—but fragile. Avoid these hacks in CI, and always prefer:
✅ Stable dependencies (avoid snapshots in prod).
✅ Reproducible builds (lock versions with mvn versions:lock-snapshots
).
✅ Regular cache cleanup (but not mid-build).
Break your cache wisely—or suffer the CI gods’ wrath