-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Only check runtimeClasspath for compatibility with target JVM version #33964
Description
Expected Behavior
Gradle should not fail the build when compileClasspath contains dependencies that are incompatible with the JavaCompile.options.release parameter. Instead, it should issue a warning to inform users of a potential mismatch, allowing them to make an informed decision.
Current Behavior (optional)
Gradle currently checks both the compileClasspath and runtimeClasspath against the value specified by JavaCompile.options.release. If it finds an incompatible dependency in either, it fails the build with an error like the following:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve com.github.spotbugs:spotbugs-annotations:4.9.3.
Required by:
project : > org.apache.logging.log4j:log4j-api:2.25.0
> No matching variant of com.github.spotbugs:spotbugs-annotations:4.9.3 was found. The consumer was configured to find a library for use during compile-time, compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally but:
[ ... ]
While checking the runtimeClasspath is essential to prevent runtime errors, enforcing the same check on compileOnly dependencies is overly strict. These dependencies are used exclusively by the compiler, annotation processors, or compiler plugins. If the JDK used in the toolchain is compatible with those dependencies, compilation will succeed.
Context
This error was reported by our Gradle users in apache/logging-log4j2#3754.
Although Gradle's heuristic aims to prevent runtime errors—a goal we fully support—in this case, it unnecessarily breaks builds for Gradle users while Maven users encounter no such problems. As a result, users cannot use Log4j 2.25.0 with Gradle, despite it being fully compatible from a runtime perspective.