Someone on the team ran mvn clean, got a hash mismatch on a plugin JAR, decided the fix was to nuke ~/.m2/repository, and then hit the build machine from a lab VLAN that has no outbound internet. Every subsequent build failed before compilation even started. The error wasn’t a compile error. It was a resolution error, which is a different animal and gets misdiagnosed constantly.
This is the scenario worth walking through, because clearing the local repo is a common panic move and it turns a recoverable build into a hard dependency on the network. The failures that follow all look like different problems but share one cause: Maven has nowhere to fetch artifacts it expects to already have on disk.
What the errors actually say
When the local repository is empty or partially wiped, Maven fails in a handful of predictable shapes. Recognizing which one you’re looking at saves time.
- Could not resolve dependencies for project … The following artifacts could not be resolved: groupId:artifactId:jar:version was not found in central during the last update. The cache is empty and the remote lookup failed or was skipped.
- Plugin … or one of its dependencies could not be resolved followed by Cannot access central in offline mode. You’re running with
-oor have<offline>true</offline>set in settings, and the plugin isn’t local. - Checksum validation failed on a plugin. Often leftover partial downloads from an interrupted clean.
- Could not find or load main class when invoking a plugin goal that silently failed to download its own JAR.
The key diagnostic move: run with -e and -X and read the resolution chain, not just the last line. The last line usually blames the parent project. The real cause is three lines up, a missing artifact in a transitive path.
First, stop assuming the repo is the problem
Before touching ~/.m2, check whether you actually have a network path to the remote. On a build box behind a proxy, the default settings.xml may point at Maven Central while your proxy needs an explicit <proxy> block. A cleared repo plus a misconfigured proxy produces exactly the “could not be resolved” message above.
We test the path separately from Maven, with a plain curl -I against the repository URL configured in settings.xml, not against central by default. If that fails, the problem is the network, not Maven. Don’t clear anything else until the network is confirmed working or you’ve decided to run offline on purpose.
The offline build, done deliberately
If the build host genuinely has no internet, a cleared repository means you must seed it from a machine that does, or from a known-good cache. Here’s the sequence that works.
On the connected machine, with the exact same pom.xml and settings, run:
mvn -B dependency:go-offline
This resolves the declared dependencies and plugins and downloads them into the local repository. It won’t catch every dynamic transitive resolution, so follow it with a real build:
mvn -B -DskipTests package
Now copy the relevant portion of the local repository to the offline host. Copying the whole ~/.m2/repository works but drags in years of junk. A cleaner approach is mvn dependency:copy-dependencies into a staging folder, though that only covers runtime deps, not plugins. For a reproducible handoff, most teams end up mirroring the repository into a shared directory or an internal Nexus/Artifactory instance.
On the offline host, point settings.xml at a file-based repository or a network share that holds the artifacts, and leave Maven in online-with-that-mirror mode rather than -o. The -o flag refuses any remote access at all, including a reachable local mirror. Use a mirror definition instead and Maven will resolve against it normally.
When the local cache is corrupt, not empty
Partial wipes leave half-downloaded files. Maven writes a .lastUpdated marker next to a failed download and will refuse to retry that artifact until the marker is gone. If you’re seeing “was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed,” that’s the marker talking.
Delete just the stale markers rather than the whole tree:
find ~/.m2/repository -name "*.lastUpdated" -delete
Then force a re-resolve with mvn -U. The -U flag forces a check for updated releases and snaps, which is often what you actually wanted when you cleared the repo in the first place. Clearing the repo is the sledgehammer; -U is the scalpel.
Plugin versions that float are the real trap
If a plugin is declared without a version, or with LATEST or RELEASE, clearing the repo can resolve to a different version than before. The build then fails with an unfamiliar error in code you didn’t touch. Pin every plugin version, including the compiler, surefire, and any custom plugin. A locked plugin version means a seeded offline repo reproduces the same build. A floating one doesn’t.
We keep a pluginManagement block with explicit versions for everything the build touches and treat an unpinned plugin as a bug in review.
Confirming you’re actually offline-safe
Once seeded, verify by disabling the network adapter or pulling the cable on the build host, then run the full build. If it passes, you’re genuinely self-contained. If it fails, each error names the artifact that’s missing from the seed. Add it to the seed list and repeat.
One detail that bites people: dependency:go-offline is not exhaustive for plugins invoked only through lifecycle bindings in a parent or profile. Run the real lifecycle goals (clean, package, install) against the seed machine and check the local repository afterward. The artifacts that appear are what the offline host needs.
What we actually recommend
Don’t clear the local repository as a first response to a resolution error. Clear a specific artifact directory, delete .lastUpdated markers, and force a re-check with -U. These solve the majority of cases without destroying the cache the build depends on.
When you do need a full reset, treat it as a planned operation: seed a mirror or a file-based repo first, point the offline settings at it, and keep plugin versions pinned. A build machine without internet should be resolving against something under your control, not reaching blindly for central. Once that’s in place, clearing the repository is a routine, boring step, which is what it should have been all along.
And keep the license details for any commercial build tooling in the same place you keep this configuration, since re-activation after a rebuild is the sort of thing that only surfaces on a deadline.
