Konrad Sztenderski
02/19/2023, 9:27 PMkotlin-dsl
plugin.
I have tried setting jvmTarget
for KotlinCompile
task:
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
or like this:
kotlinDslPluginOptions {
jvmTarget.set("11")
}
setting toolchain like this:
kotlin.jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(11))
}
but when I add kotlin-dsl
to plugins then code doesn't compile because of API I used from java 9, so it seems like it still uses jvm 8.
Without kotlin-dsl
everything builds fine.Chris Lee
02/19/2023, 9:29 PMafterEvaluate {
tasks.withType<KotlinCompile>().configureEach {
}
}
Note: use of afterEvaluate
is generally discouraged. This is a special case as it is the only way to override what the plugin does (ideally it should not be using afterEvaluate).Chris Lee
02/19/2023, 9:30 PMChris Lee
02/19/2023, 9:31 PMephemient
02/19/2023, 9:43 PMKonrad Sztenderski
02/19/2023, 9:44 PMif (this@kotlinDslPluginOptions.jvmTarget.isPresent) {
jvmTarget.set(JvmTarget.fromTarget(this@kotlinDslPluginOptions.jvmTarget.get()))
}
Chris Lee
02/19/2023, 9:55 PMKonrad Sztenderski
02/19/2023, 9:59 PMit.kotlinOptions {
jvmTarget = this@kotlinDslPluginOptions.jvmTarget.get()
...
}
And unfortunately configuring it in afterEvaluate
doesn't help.Chris Lee
02/19/2023, 10:00 PMChris Lee
02/19/2023, 10:03 PMconfigure<KotlinDslPluginOptions> {
jvmTarget.value = "17"
}
Chris Lee
02/19/2023, 10:04 PM// afterEvaluate required as kotlin dsl plugin sets its defaults in afterEvaluate
// <https://github.com/gradle/gradle/blob/master/subprojects/kotlin-dsl-plugins/src/main/kotlin/org/gradle/kotlin/dsl/plugins/dsl/KotlinDslCompilerPlugins.kt#L43>
afterEvaluate {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
}
}
}
Chris Lee
02/19/2023, 10:05 PMKonrad Sztenderski
02/19/2023, 10:17 PMjvmTarget = this@kotlinDslPluginOptions.jvmTarget.get()
then jvmTarget
is set to "11" indeed but somehow my code still doesn't compile.Chris Lee
02/19/2023, 10:17 PMKonrad Sztenderski
02/19/2023, 10:20 PMUnresolved reference: newDefaultInstance
and whole source code is:
fun main(args: Array<String>) {
TransformerFactory.newDefaultInstance()
}
Konrad Sztenderski
02/19/2023, 10:20 PMnewDefaultInstance
method is from java 9Chris Lee
02/19/2023, 10:21 PMfun main(args: Array<String>)
in a kotlin-dsl project, which is by definition creating a Gradle plugin, not otherwise executable Kotlin code.ephemient
02/19/2023, 10:22 PMephemient
02/19/2023, 10:22 PMephemient
02/19/2023, 10:23 PMChris Lee
02/19/2023, 10:23 PMkotlin("jvm")
instead of kotlin-dsl
.ephemient
02/19/2023, 10:23 PMephemient
02/19/2023, 10:23 PMephemient
02/19/2023, 10:25 PMKonrad Sztenderski
02/19/2023, 10:25 PMkotlin("jvm")
and kotlin-dsl
in gradle plugin source code. Previous code is only for testing against smaller source code.ephemient
02/19/2023, 10:26 PMChris Lee
02/19/2023, 10:26 PMephemient
02/19/2023, 10:26 PMephemient
02/19/2023, 10:27 PMdependencies { implementation(gradleApi()) }
ephemient
02/19/2023, 10:28 PMKonrad Sztenderski
02/19/2023, 10:40 PMkotlin("jvm")
and left only kotlin-dsl
it doesn't workephemient
02/19/2023, 10:41 PMephemient
02/19/2023, 10:41 PMjava.xml
API newer tha Java 8 is simply not going to work, regardless of which Java you're building or running Gradle withKonrad Sztenderski
02/19/2023, 10:41 PM