Skip to content
Latchkey

Maven "BUILD FAILURE - Could not find artifact (SNAPSHOT)" - Fix in CI

Maven could not resolve a -SNAPSHOT dependency. Either the snapshot was never published to the repository CI can reach, the snapshot repository is not declared, or the metadata fetch dropped mid-transfer on a flaky network.

What this error means

The build fails with BUILD FAILURE and Could not find artifact com.example:lib:jar:1.2.0-SNAPSHOT in snapshots, or Could not transfer metadata ... maven-metadata.xml when the snapshot repo is unreachable.

maven
[ERROR] Failed to execute goal on project app: Could not resolve dependencies
for project com.example:app:jar:1.0.0: Could not find artifact
com.example:lib:jar:1.2.0-SNAPSHOT in snapshots
(https://nexus.example.com/repository/maven-snapshots/)

Diagnose it: resolve the effective POM first

Maven merges parent POMs, profiles, and settings before it builds anything. The configuration causing your failure is frequently inherited or activated by a profile that is on locally and off in CI.

Terminal
# the fully resolved configuration Maven will actually use
mvn help:effective-pom | head -60

# which profiles are active here vs on your machine?
mvn help:active-profiles

# full error, offline-safe, no colour codes to confuse the log
mvn -B -e -X <goal> 2>&1 | tail -60

Common causes

The SNAPSHOT was never deployed

The upstream module that produces the snapshot has not run mvn deploy, so no build of it exists in the snapshot repo.

Snapshot repository not declared or snapshots disabled

The repo entry has <snapshots><enabled>false</enabled></snapshots>, or the snapshot repo is simply not configured, so Maven never looks there.

Transient network drop fetching snapshot metadata

Snapshots are re-resolved every build via maven-metadata.xml; a momentary network blip during that fetch fails resolution even though the artifact exists.

How to fix it

Enable and declare the snapshot repository

Make sure Maven is told where snapshots live and that snapshots are enabled.

pom.xml
<repository>
  <id>company-snapshots</id>
  <url>https://nexus.example.com/repository/maven-snapshots/</url>
  <snapshots><enabled>true</enabled></snapshots>
</repository>

Force a fresh snapshot re-resolve

Rule out stale or partial snapshot metadata in the local cache.

Terminal
mvn -U clean verify
# -U forces an update check for SNAPSHOT metadata

Deploy the upstream snapshot first

If the artifact truly is absent, publish it from the producing module.

Terminal
mvn -q deploy   # in the lib module, so the SNAPSHOT exists for consumers

How to prevent it

  • Prefer released versions over SNAPSHOTs for shared CI dependencies.
  • Declare snapshot repositories explicitly with snapshots enabled.
  • Use a proxy repo so snapshot metadata is cached and resolution is resilient.

Frequently asked questions

What causes Maven "BUILD FAILURE?
There are 3 common causes: the snapshot was never deployed, snapshot repository not declared or snapshots disabled, and transient network drop fetching snapshot metadata. The upstream module that produces the snapshot has not run mvn deploy, so no build of it exists in the snapshot repo.
How do I fix Maven "BUILD FAILURE?
There are 3 fixes depending on which cause you have: enable and declare the snapshot repository, force a fresh snapshot re-resolve, and deploy the upstream snapshot first. Work through them in order, since the first is the most common.
What does Maven "BUILD FAILURE actually mean?
The build fails with BUILD FAILURE and Could not find artifact com.example:lib:jar:1.2.0-SNAPSHOT in snapshots, or Could not transfer metadata ...
How do I stop Maven "BUILD FAILURE happening again?
Prefer released versions over SNAPSHOTs for shared CI dependencies. The prevention section lists 3 changes that keep it from recurring.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card