Hi! For my java projects I can write the followin...
# gradle
t
Hi! For my java projects I can write the following in my Gradle file:
Copy code
java.targetCompatibility = JavaVersion.1_8
Is there a similar way I can set the
jvmTarget
for my Kotlin code?
c
Copy code
kotlin {
   jvmTarget.value = JavaVersion.1_8
}
t
@Chris Lee I can't seem to find the
jvmTarget
field...
c
apologies, that was for Kotlin Gradle DSL; this is for straight-up Kotlin:
Copy code
tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
e
if you use the Kotlin extension instead
Copy code
kotlin {
    target {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
you will only have to change
target
to
targets.all
when moving to Kotlin Multiplatform
t
Better to use Gradle JVM toolchain feature that works both for Java and Kotlin: https://kotl.in/gradle/jvm/toolchain
it as well configures `jvmTarget`/`targetCompatibility`
t
@tapchicoma It seems like I can just write
Copy code
kotlin.jvmToolchain(8)
Is that right?
t
Yes, this shortcut was added in 1.7.20 release
already existing configuration approach is still there if you need more specific toolchain configuration