Ask Your Question
1

In build.gradle.kts, how can I ensure that the jvm target compatibility for the 'compileJava' task (11) and the 'compileKotlin' task (1.8) are both set to the same Java version?

asked 2023-07-01 08:11:06 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-01 08:37:02 +0000

plato gravatar image

To ensure that the jvm target compatibility for the 'compileJava' task (11) and the 'compileKotlin' task (1.8) are both set to the same Java version, you can add the following code to your build.gradle.kts file:

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "11"
}

tasks.withType<JavaCompile> {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

This code sets the jvm target compatibility for the 'compileKotlin' task to 11, and sets the sourceCompatibility and targetCompatibility for the 'compileJava' task to JavaVersion.VERSION_11, ensuring that both tasks are using the same Java version.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-01 08:11:06 +0000

Seen: 12 times

Last updated: Jul 01 '23