We Are Going To Discuss About How to set compileJava’ task ( 11) and ‘compileKotlin’ task (1.8) jvm target compatibility to the same Java version in build.gradle.kts?. So lets Start this Java Article.
How to set compileJava’ task ( 11) and ‘compileKotlin’ task (1.8) jvm target compatibility to the same Java version in build.gradle.kts?
- How to set compileJava' task ( 11) and 'compileKotlin' task (1.8) jvm target compatibility to the same Java version in build.gradle.kts?
You can set java version for java with
java { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 }
or alternatively:java { toolchain.languageVersion.set(JavaLanguageVersion.of(11)) }
- compileJava' task ( 11) and 'compileKotlin' task (1.8) jvm target compatibility to the same Java version in build.gradle.kts?
You can set java version for java with
java { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 }
or alternatively:java { toolchain.languageVersion.set(JavaLanguageVersion.of(11)) }
Solution 1
You can set java version for java with
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
or alternatively:
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(11))
}
and for kotlin with:
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
}
}
All samples are in gradle kotlin dsl.
Original Author Of This Content
Solution 2
@Marian’s answer didn’t quite help me.
I end up setting the following in the app build.gradle
Android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget=11
}
...
}
Original Author Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.