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.
> 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.pomDiagnose 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.
# 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 -versionCommon 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.
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.
./gradlew :app:dependencyInsight --dependency com.example:lib
./gradlew :app:dependencies --configuration runtimeClasspathConfiguration 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=warnfirst 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.