Targeting JVM 1.8 on Kotlin with Gradle is as easy as
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
But that doesn't work for Java 9 if I simply change the jvmTarget
to 9
or 1.9
. How can I do it?
Targeting JVM 1.8 on Kotlin with Gradle is as easy as
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
But that doesn't work for Java 9 if I simply change the jvmTarget
to 9
or 1.9
. How can I do it?
Kotlin目前只针对Java6和Java8
See the FAQs here https://kotlinlang.org/docs/reference/faq.html#does-kotlin-only-target-java-6
现在说
Kotlin是否只针对Java 6?
编辑:
So... because it's the compatibility of the bytecode that kotlin is generating it doesn't mean that fixes the Java version you need to use.
Here's a gradle file that let's you use Java 11 alongside kotlin generating Java 8 compatible bytecode
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.71'
}
group 'com.dambra.paul.string-calculator'
version '0.0.0'
sourceCompatibility = 11.0
repositories {
mavenCentral()
}
dependencies {
testImplementation(
'org.junit.jupiter:junit-jupiter-api:5.1.0'
)
testRuntimeOnly(
'org.junit.jupiter:junit-jupiter-engine:5.1.0'
)
testCompile("org.assertj:assertj-core:3.11.1")
testCompile 'org.junit.jupiter:junit-jupiter-params:5.1.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
You can't "target jvm 9" with Kotlin. But you can write Kotlin alongside Java (9|10|11|etc)