Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 666
Combo Avatar asked Mar 27 '18 09:03

Combo


1 Answers

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.

like image 138
zsmb13 Avatar answered Oct 23 '22 09:10

zsmb13