Skip to content
javahacks.dev
DevOps

Fix Gradle Could Not Resolve All Files for Configuration

Fix the Gradle error about resolving a configuration by adding repositories, matching Java versions with a toolchain and reading the nested cause.

6 min read
Summarize in AI
Flat illustration of a log with a failing line and a wrench, with the Gradle, Docker, Spring and OpenJDK logos.

Gradle reports a dependency failure against a configuration, which is a named bucket of dependencies such as the compile classpath of the main source set:

Text
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find com.example:billing-lib:2.3.1.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/com/example/billing-lib/2.3.1/billing-lib-2.3.1.pom

The first two lines are identical for every resolution failure. The line under them is the real error, and the fix depends entirely on what it says. Treat the headline as a label and read the nested > lines from the bottom up. The configuration name matters too: :compileClasspath failed at compile time, :runtimeClasspath at packaging, :testCompileClasspath only for tests. If only the test classpath fails, the missing library is a test dependency or a repository the test configuration cannot see.

The Maven counterpart is could not resolve dependencies. What is particular to Gradle is variant matching, which is the second cause below. The examples assume Gradle 8 with the Kotlin DSL.

Match the nested message to the cause

Nested line saysCauseGo to
Could not find group:name:version with an empty "Searched in" listNo repository declaredCause 1
No matching variant ... compatible with Java 21The build uses an older Java than the libraryCause 2
Could not find ...:. with an empty versionNo version, and nothing supplies oneCause 3
Could not GET, Connect timed out, PKIX path building failedNetwork, proxy or TLSCause 4
Received status code 401 or 403Credentials for a private repositoryCause 4

Cause 1: no repository, or the wrong place for it

build.gradle.ktskotlin
repositories {
    mavenCentral()
}

A project with no repositories block has nowhere to look, and the "Searched in the following locations" list shows exactly what Gradle tried. An empty list means none are configured.

Repositories can also be declared centrally, in settings.gradle.kts, and many company templates do that:

settings.gradle.ktskotlin
dependencyResolutionManagement {
    repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
    repositories {
        mavenCentral()
        maven("https://repo.example.test/releases")
    }
}

With FAIL_ON_PROJECT_REPOS, a repositories block inside a module's build file is an error, and with PREFER_SETTINGS it is silently ignored. Either way, a repository you added in the module never gets searched, which looks exactly like a missing repository. Put it in settings, or change the mode if the project genuinely needs per-module repositories.

When the artifact lives in a private repository, limit it to the groups it serves so Gradle does not ask it for everything and so a typo-squatted public artifact cannot shadow it:

kotlin
maven("https://repo.example.test/releases") {
    content { includeGroup("com.example") }
}

Cause 2: the library wants a newer Java

Text
> Could not resolve com.example:billing-lib:3.0.0.
  Required by: project :
     > No matching variant of com.example:billing-lib:3.0.0 was found. The consumer was configured to find a library for use during compile-time, compatible with Java 17, ... but:
         - Variant 'apiElements' declares a library, compatible with Java 21

Gradle publishes the minimum Java version in the module metadata of libraries that declare it, and resolution compares that against the Java version of your build. This is the only cause where the library is found and still rejected. Lowering the library version is a workaround that hides a real mismatch. Fix the build to use the JDK you intend, and declare it as a toolchain so it no longer depends on whichever JDK launched Gradle:

kotlin
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

Gradle looks for a matching installed JDK, and downloads one when a toolchain resolver such as the Foojay plugin is applied in settings.gradle.kts. Gradle itself still needs a JDK it supports to start, and ./gradlew --version prints which one that is. The Maven side of the same mismatch is covered in invalid target release.

Cause 3: a missing or misspelled coordinate

kotlin
dependencies {
    implementation(platform("org.springframework.boot:spring-boot-dependencies:3.5.0"))
    implementation("org.springframework.boot:spring-boot-starter-web")
}

The second line has no version. It resolves here because the platform(...) line above supplies one through the Spring Boot BOM. Remove the platform and Gradle fails with Could not find org.springframework.boot:spring-boot-starter-web:. and a trailing dot, which is the empty version. The same thing happens when a version catalog entry exists but the alias is spelled differently in the build file; that one fails earlier, in script compilation, and is a different error.

Copy the coordinate from the library's own documentation rather than from a blog, and check the three parts one at a time: group, artifact, version. A common slip is the group of a relocated project, for example the move from javax.* to jakarta.* artifacts.

Cause 4: network, proxy, TLS and credentials

Could not GET followed by a URL and a timeout is the network. Corporate proxies are configured in gradle.properties, either in the project or in ~/.gradle:

properties
systemProp.https.proxyHost=proxy.example.test
systemProp.https.proxyPort=3128

PKIX path building failed means a proxy re-signs TLS traffic with a certificate the JVM does not trust, which is a trust-store problem and not a Gradle one; see the PKIX fix. A 401 or 403 from a private repository needs credentials, and they belong in ~/.gradle/gradle.properties or environment variables, never in the build file:

kotlin
maven("https://repo.example.test/releases") {
    credentials {
        username = providers.gradleProperty("repoUser").orNull
        password = providers.gradleProperty("repoPassword").orNull
    }
}

Cached failures and offline mode

Gradle caches negative results as well as positive ones. After a repository outage, a build can keep failing for a while even though the artifact is back. Ask Gradle to ignore its cache once:

Shell
./gradlew build --refresh-dependencies

Also check whether --offline is set on the command line or in gradle.properties, because an offline build can only use what is already in ~/.gradle/caches.

See the whole graph

Shell
./gradlew dependencies --configuration compileClasspath
./gradlew dependencyInsight --dependency billing-lib --configuration compileClasspath

dependencies prints the tree and marks anything unresolved with FAILED. dependencyInsight explains why one version was selected, which is how you find the dependency that quietly forces an older version of a library you declared newer.

Verification metadata and locked dependencies

Two features can make a resolution fail although the artifact exists and the repository is reachable. Dependency verification, enabled with a gradle/verification-metadata.xml file, checks the checksums of every downloaded artifact, and a missing or mismatched entry fails the build with a message naming the file and the expected hash. Update the metadata deliberately with ./gradlew --write-verification-metadata sha256 help and review the diff, and never regenerate it to silence a failure you do not understand, because a changed checksum can mean a tampered artifact. Dependency locking pins every version in lock files, and adding a dependency without updating the lock fails; refresh it with --write-locks. Both appear in the nested lines of the error, so read them before assuming the network is at fault.

What this error does not cover

A failure to resolve a Gradle plugin reads Plugin [id: '...'] was not found in any of the following sources, and it is fixed in the pluginManagement { repositories { ... } } block of settings.gradle.kts, not in the project repositories above. The primary sources are the dependency management chapter and the toolchains chapter of the Gradle user guide.

Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.