Skip to content
Latchkey

Gradle "Could not resolve" Dependency - Fix in CI

Gradle could not locate a dependency in any repository declared in the build. Either the coordinates are wrong, the repository is missing from the repositories {} block, or the artifact is not published where Gradle looked.

What this error means

The build fails during configuration or resolution with Could not resolve <group:name:version> and Could not find/Required by: lines showing the path to the missing artifact. No compilation happens.

gradle output
> Could not resolve com.example:lib:2.3.1.
  Required by:
      project :app
   > Could not find com.example:lib:2.3.1.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/com/example/lib/2.3.1/lib-2.3.1.pom

Diagnose it: get the real failure out of Gradle

Gradle summarises failures aggressively, and the top-level message frequently describes a downstream symptom rather than the cause. Re-run the failing task with diagnostics before changing build logic.

Terminal
# the actual stack, plus what Gradle decided about the build
./gradlew <task> --stacktrace --info

# is a stale daemon or cache involved?
./gradlew --stop
./gradlew <task> --no-daemon --no-build-cache

# what does Gradle think the environment is?
./gradlew -version

Common causes

Repository not declared

Gradle only searches repositories you list in repositories {}. An internal or vendor artifact is invisible unless that repo (and its credentials) is declared.

Wrong coordinates or version

A typo in group/name or a version that was never published means no repository can serve it.

How to fix it

Declare the repository that holds the artifact

Add the hosting repository to the build’s repositories block.

build.gradle.kts
repositories {
    mavenCentral()
    maven {
        url = uri("https://nexus.example.com/repository/maven-releases/")
    }
}

Inspect the resolution path

See exactly which configuration pulls the dependency and where Gradle searched.

Terminal
./gradlew :app:dependencyInsight --dependency com.example:lib
./gradlew :app:dependencies --configuration runtimeClasspath

Configuration cache and CI

  • The configuration cache rejects build logic that reads mutable state at execution time, which is why enabling it surfaces errors an existing build never showed.
  • Run with --configuration-cache-problems=warn first to see the full list rather than failing on the first one.
  • A cached configuration keyed to a different environment is worse than none. Include the JDK version in your cache key.

How to prevent it

  • Declare all repositories (including internal) centrally in settings.gradle dependencyResolutionManagement.
  • Use a version catalog so coordinates are defined once and reused.
  • Cache the Gradle dependency cache in CI keyed on the lockfile/build scripts.

Frequently asked questions

What causes Gradle "Could not resolve" dependency?
There are 2 common causes: repository not declared and wrong coordinates or version. Gradle only searches repositories you list in repositories {}.
How do I fix Gradle "Could not resolve" dependency?
There are 2 fixes depending on which cause you have: declare the repository that holds the artifact and inspect the resolution path. Work through them in order, since the first is the most common.
What does Gradle "Could not resolve" dependency actually mean?
The build fails during configuration or resolution with Could not resolve <group:name:version> and Could not find/Required by: lines showing the path to the missing artifact.
How do I stop Gradle "Could not resolve" dependency happening again?
Declare all repositories (including internal) centrally in settings.gradle dependencyResolutionManagement. The prevention section lists 3 changes that keep it from recurring.

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