Combo
Combo

Reputation: 1005

Kotlin compile to java 1.8

How to set in gradle and in maven to compile and use jvm with Java 1.8?

gradle

compileKotlin.sourceCompatibility = JavaVersion.VERSION_1_8
compileKotlin.targetCompatibility = JavaVersion.VERSION_1_8
compileKotlin.kotlinOptions.jvmTarget = "1.8"

is this ok?

Upvotes: 6

Views: 6867

Answers (1)

zsmb13
zsmb13

Reputation: 89548

There isn't a sourceCompatibility or targetCompatibility setting for the Kotlin compiler, you only need the jvmTarget option, which you got right. You might want to set it for your tests as well. Overall, this is the config you need:

compileKotlin.kotlinOptions.jvmTarget = "1.8"
compileTestKotlin.kotlinOptions.jvmTarget = "1.8"

Alternatively, with different formatting:

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

Based on the documentation about using Kotlin with Gradle.

Upvotes: 10

Related Questions