How to set compileJava’ task ( 11) and ‘compileKotlin’ task (1.8) jvm target compatibility to the same Java version in build.gradle.kts?

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?

Advertisements
  1. 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)) }

  2. 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

Advertisements

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

Advertisements

@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

Advertisements

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Advertisements
Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment