I created a simple Gradle build (kts) to test the configuration of failOnVersionConflict() as follows:
plugins {
java
}
repositories {
mavenCentral()
}
configurations.all {
resolutionStrategy {
// Force Gradle to fail when different versions of the same dependency appear
failOnVersionConflict()
}
}
dependencies {
// Transitively pulls in Google Protobuf (Java) 4.32.0
implementation("build.buf:protovalidate:1.0.0")
implementation("com.google.guava:guava:32.1.3-jre")
// Transitively pulls in Google Guava 31.x
implementation("com.google.inject:guice:7.0.0")
// Transitively pulls in Google Protobuf (Java) 3.25.5
implementation("io.grpc:grpc-protobuf:1.75.0")
}
I was expecting a build failure due to conflicting dependencies. The dependency graph clearly shows the conflicting (FAILED) dependencies:
% gradle dependencies --configuration compileClasspath
> Task :dependencies
------------------------------------------------------------
Root project 'gradle-dependency-resolution-strategy-fail-on-conflict-example'
------------------------------------------------------------
compileClasspath - Compile classpath for source set 'main'.
+--- build.buf:protovalidate:1.0.0
| +--- org.jspecify:jspecify:1.0.0
| \--- com.google.protobuf:protobuf-java:4.32.0 FAILED
+--- com.google.guava:guava:32.1.3-jre FAILED
+--- com.google.inject:guice:7.0.0
| +--- jakarta.inject:jakarta.inject-api:2.0.1
| +--- aopalliance:aopalliance:1.0
| \--- com.google.guava:guava:31.0.1-jre FAILED
\--- io.grpc:grpc-protobuf:1.74.0
+--- io.grpc:grpc-api:1.74.0
| +--- com.google.code.findbugs:jsr305:3.0.2
| \--- com.google.errorprone:error_prone_annotations:2.30.0 FAILED
+--- com.google.code.findbugs:jsr305:3.0.2
+--- com.google.protobuf:protobuf-java:3.25.5 FAILED
\--- com.google.api.grpc:proto-google-common-protos:2.51.0
\--- com.google.protobuf:protobuf-java:3.25.5 FAILED
(*) - Indicates repeated occurrences of a transitive dependency subtree. Gradle expands transitive dependency subtrees only once per project; repeat occurrences only display the root of the subtree, followed by this annotation.
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
The Gradle project is using Gradle 8.14 on JDK 17:
% gradle -version
------------------------------------------------------------
Gradle 8.14.3
------------------------------------------------------------
Build time: 2025-07-04 13:15:44 UTC
Revision: e5ee1df3d88b8ca3a8074787a94f373e3090e1db
Kotlin: 2.0.21
Groovy: 3.0.24
Ant: Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM: 17.0.13 (Amazon.com Inc. 17.0.13+11-LTS)
Daemon JVM: /Users/jxblum/.sdkman/candidates/java/17.0.13-amzn (no JDK specified, using current Java home)
OS: Mac OS X 15.7.1 aarch64
I am not certain what I am doing wrong.
Should the build.gradle.kts as configured cause the Gradle build to fail?
If it would have tried to resolve the dependencies, it would have failed.
But as you can see from “in 327ms” and
“1 actionable task: 1 up-to-date”, you see that nothing happened in that build. You probably have no source files that could be compiled, so the dependencies are not resolved, so it does not fail.
For others reference, after I added a Dummy.java file:
package com.example;
public class Dummy {
}
The build failed as expected:
% gradle build
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve com.google.guava:guava:33.5.0-jre.
Required by:
root project :
> Conflict found for module 'com.google.guava:guava': between versions 33.5.0-jre and 31.0.1-jre
> Could not resolve com.google.protobuf:protobuf-java:4.32.0.
Required by:
root project : > build.buf:protovalidate:1.0.0
> Conflict found for module 'com.google.protobuf:protobuf-java': between versions 4.32.0 and 3.25.8
> Could not resolve com.google.errorprone:error_prone_annotations:2.41.0.
Required by:
root project : > com.google.guava:guava:33.5.0-jre
> Conflict found for module 'com.google.errorprone:error_prone_annotations': between versions 2.41.0 and 2.30.0
> There are 3 more failures with identical causes.
* Try:
> Run with :dependencyInsight --configuration compileClasspath --dependency com.google.guava:guava to get more insight on how to solve the conflict.
> Run with :dependencyInsight --configuration compileClasspath --dependency com.google.protobuf:protobuf-java to get more insight on how to solve the conflict.
> Run with :dependencyInsight --configuration compileClasspath --dependency com.google.errorprone:error_prone_annotations to get more insight on how to solve the conflict.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 358ms
1 actionable task: 1 executed
Then, this has a similar effect to “use the latest/highest version” (the default) or forcing a specific version, (which, for some dependencies, might result in a downgrade).
By applying the Spring gRPC (0.11.0) BOM as shown above, the result of build is then:
% gradle build
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve com.google.guava:guava:33.5.0-jre.
Required by:
root project :
> Conflict found for module 'com.google.guava:guava': between versions 33.5.0-jre and 31.0.1-jre
> Could not resolve com.google.errorprone:error_prone_annotations:2.41.0.
Required by:
root project : > com.google.guava:guava:33.5.0-jre
> Conflict found for module 'com.google.errorprone:error_prone_annotations': between versions 2.41.0 and 2.30.0
> There are 2 more failures with identical causes.
* Try:
> Run with :dependencyInsight --configuration compileClasspath --dependency com.google.guava:guava to get more insight on how to solve the conflict.
> Run with :dependencyInsight --configuration compileClasspath --dependency com.google.errorprone:error_prone_annotations to get more insight on how to solve the conflict.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 613ms
1 actionable task: 1 executed
That is the, Google Protobuf error goes away since the Spring gRPC (0.11.0) BOM declares Protobuf 4.31.1 (see here and here).
Of course, if you force a version, you did resolve the version conflict by making a decision.
The functionality only fails if there are multiple possible versions that are in conflict and you did not decide which to use.
Besides that under normal circumstances, you should never use enforcedPlatform. It is a very heavy last-resort kind of hammer for special hairy situations.
Well resolving such conflicts you configured to fail might be one, no idea.