Skip to content
Latchkey

Maven "Cannot access central in offline mode" in CI

The build was started in offline mode (-o or <offline>true</offline>), so Maven may not contact any remote repository. The requested artifact is not in the local ~/.m2 repository, and offline mode forbids downloading it.

What this error means

Resolution fails with "Cannot access central (...) in offline mode and the artifact ... has not been downloaded from it before." It only happens when the job runs mvn -o.

mvn output
[ERROR] Failed to execute goal on project app: Could not resolve dependencies for
project com.example:app:jar:1.0.0: Cannot access central
(https://repo.maven.apache.org/maven2) in offline mode and the artifact
org.apache.commons:commons-lang3:jar:3.14.0 has not been downloaded from it before. -> [Help 1]

Common causes

Offline build with an empty or partial local repo

The CI job runs mvn -o but the local .m2 cache was never populated with this dependency, so there is nothing to resolve from.

A new dependency was added after the cache was primed

A dependency added since the last online resolve is missing from the cached repository, and offline mode cannot fetch it.

How to fix it

Prime the local repository online first

  1. Run an online resolve step (mvn dependency:go-offline) to download everything.
  2. Cache ~/.m2/repository between jobs.
  3. Then run the build with -o against the warm cache.
Terminal
mvn -B dependency:go-offline
mvn -B -o verify

Drop offline mode if the cache cannot be guaranteed

Remove -o so Maven can fetch newly added artifacts, or only enable offline once go-offline has run successfully.

Terminal
mvn -B verify

How to prevent it

  • Run dependency:go-offline before any offline build.
  • Cache ~/.m2/repository keyed on the POM/lock hash.
  • Re-prime the cache whenever dependencies change.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →