How specify the required Java version in a Gradle build

后端 未结 4 911
长发绾君心
长发绾君心 2021-01-07 19:06

I would like to set in a Gradle build file the required Java version e.g. 7 or 8 without having to specify the actual path to a local JDK installation.

Is

4条回答
  •  借酒劲吻你
    2021-01-07 19:36

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

    // build.gradle.kts
    
    plugins {
        id("java-library") // or id("application")
    }
    
    java {
        toolchain {
            languageVersion.set(JavaLanguageVersion.of(11))
        }
    }
    

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

提交回复
热议问题