How do I specify the required Java version in a Gradle build?

This feature was just added to Gradle 6.7 as Java toolchains:

// build.gradle.kts

plugins {
    id("java-library") // or id("application")

java {
    toolchain {

With this in place Gradle will automatically download & use the appropriate JDK (using AdoptOpenJDK by default) for the specified Java version.

Leave a Comment