I have a Gradle build consisting of multiple Java 8 projects and I want to add a Spring Boot project that uses Java 21.
I tried running the Gradle build with Java 21, but the existing projects use things in Java 8 that don’t exist in Java 21 and I don’t have the time at the moment to migrate them to Java 21.
I’m therefore building using Gradle version 8.7 on Windows with Java 8 and using a toolchain (set up in the parent build.gradle) to set the Java version to 21 for the new project. This works until I try to add the Spring Boot plugin.
Here’s my build.gradle:
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'org.springframework.boot' version '3.2.5'
}
This gives the error:
No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.2.5 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute ‘org.gradle.plugin.api-version’ with value ‘8.7’ but:
- Variant ‘apiElements’ declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 8
- Other compatible attribute:
- Doesn’t say anything about org.gradle.plugin.api-version (required ‘8.7’)
How can I get the Java 21 toolchain applied to the Spring Boot plugin?
Stephen Muir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.