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
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: