How specify the required Java version in a Gradle build

后端 未结 4 952
长发绾君心
长发绾君心 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:14

    You can try this:

    java {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    
    tasks.withType {
        options.compilerArgs.addAll(arrayOf("--release", "8"))
    }
    

    This will also give JDK compliance to you. You can also see the following related issues:

    • Gradle: [Java 9] Add convenience method for -release compiler argument
    • Eclipse Plug-ins for Gradle: JDK API compatibility should match the sourceCompatibility option.

提交回复
热议问题