It is not possible to have JDK <17 for running Gradle and only configure the Gradle toolchain to use JDK 17. (I am not sure if the toolchain feature even supports this as the plugin itself requires JDK 17.)

Environment - JDK 8 or 11 (for running Gradle) - Gradle 7.5.1 - Spring Boot 3.0.0

build.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.0'
}

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

Output

$ gradle clean

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'demo'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.0.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.0
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.0 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5.1' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')
          - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')
          - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')
          - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')
          - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')
          - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')

Comment From: wilkinsona

Spring Boot 3.0 requires Java 17, both at runtime and for running Maven and Gradle. Is there a particular reason why you need to run Gradle on Java 8 or 11? Boot 3.0 requires Gradle 7.5+ which supports Java 17.

Comment From: darxriggs

I have been using the toolchain feature so far to make builds as independent as possible from the environment where Gradle is running on.

If Java 17 is also required to run Gradle for Spring Boot 3 this is also fine as it marks a clear cut.

Comment From: wilkinsona

Thanks for following up.

Comment From: lancedfr

When our projects go beyond Java 17 support for this would be nice

Comment From: sbreakey

A pity this is declined, as @darxriggs says, it is nice to be able to keep the build as independent from the env gradle runs on as possible.

We stumbled over this for a bit before we figured out the reason.

In our org almost all services are on boot 2.7.x, and using java 11. As such our jenkins agent is jdk11.

We struggled / failed to get time allocated from business for a jdk17 jenkins agent to be built, and using the toolchain feature would conveniently eliminate that problem.

Comment From: wilkinsona

and using the toolchain feature would conveniently eliminate that problem

Unfortunately, that's not the case. Toolchain support only affects the JVM that Gradle uses for things like compilation and test execution. It would not allow Gradle running on Java 11 to load a plugin that requires Java 17.

The only way to address this would be for Spring Boot's Gradle plugin and everything upon which it depends to stop requiring Java 17. Unfortunately, that won't happen as, among other things, the plugin depends on org.springframework:spring-core which requires Java 17 as of Spring Framework 6.

Comment From: sbreakey

AH, well that I did not know, thanks for the info @wilkinsona