Vitali Plagov
01/09/2023, 10:06 AMbuild.gradle
compileKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}
}
The IDEA warns me that kotlinOptions
is deprecated. I can’t find the option how to replace this with a proper syntax. Can anyone please help me? Gradle 7.2, Kotlin 1.8.0mudasar187
01/09/2023, 10:07 AMwithType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
inside tasks {}
definitionmudasar187
01/09/2023, 10:10 AMVitali Plagov
01/09/2023, 10:11 AMtasks {}
definition. Tasks that I have in the build script are defined on the root levelmbonnin
01/09/2023, 10:11 AMmbonnin
01/09/2023, 10:11 AMcompilerOptions
, I'd go with thatmudasar187
01/09/2023, 10:11 AMcompileKotlin {
kotlinOptions.jvmTarget = '17'
}
In another project without warningmbonnin
01/09/2023, 10:12 AMVitali Plagov
01/09/2023, 10:13 AMmbonnin
01/09/2023, 10:13 AMkotlinOptions
in one of the syntax above, I'm pretty sure it should be the case for all other syntaxes that use kotlinOptions
, whether you use Groovy, Kotlin, withType
or compileKotlin
, etc...Vitali Plagov
01/09/2023, 10:14 AMVitali Plagov
01/09/2023, 10:14 AMmbonnin
01/09/2023, 10:14 AMmbonnin
01/09/2023, 10:15 AMmbonnin
01/09/2023, 10:15 AMVitali Plagov
01/09/2023, 10:16 AMtapchicoma
01/09/2023, 10:20 AMfun kotlinOptions(fn: Closure<*>) { ... }
Generally it is not related to compilerOptions
, but still you should to migrate to them. kotlinOptions
will be deprecated once IDEA will have proper support for migration from kotlinOptions
mbonnin
01/09/2023, 10:21 AMVitali Plagov
01/09/2023, 10:22 AMVitali Plagov
01/09/2023, 10:22 AMcompileKotlin {
kotlinOptions.jvmTarget = '17'
}
this?tapchicoma
01/09/2023, 10:23 AMcompileKotlin {
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
mudasar187
01/09/2023, 10:27 AMtapchicoma
01/09/2023, 10:37 AMtasks.named<org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile>("compileKotlin") {
compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
tapchicoma
01/09/2023, 10:38 AMVampire
01/09/2023, 10:44 AMtasks.compileKotlin { compilerOptions... }
for Kotlin DSL.tapchicoma
01/09/2023, 10:45 AMtapchicoma
01/09/2023, 10:46 AMCarter
01/09/2023, 12:33 PM* What went wrong:
Task with name 'compileKotlin' not found in project ':app'.
mbonnin
01/09/2023, 12:50 PMcompileKotlinJvm
or so. You can certainly apply to all tasks. Maybe something like this:
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>() {
compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
mbonnin
01/09/2023, 12:50 PMVampire
01/09/2023, 12:51 PMtasks.withType<...>() { ... }
but tasks.withType<...>().configureEach { ... }
or all tasks of that type get realized and configured prematurely instead only when needed.mbonnin
01/09/2023, 12:52 PMCarter
01/09/2023, 3:11 PMconfigureEach
.
Related, how does one get the output of the build to target older JVM versions while building with newer JVM versions?
I currently get this build warning if I use toolchains.
'compileJava' task (current target is 17) and 'compileKotlinJvm' task (current target is 11) jvm target compatibility should be set to the same Java version.
By default will become an error since Gradle 8.0+! Read more: <https://kotl.in/gradle/jvm/target-validation>
Consider using JVM toolchain: <https://kotl.in/gradle/jvm/toolchain>
Vampire
01/09/2023, 3:12 PMmbonnin
01/09/2023, 3:12 PMCarter
01/09/2023, 3:13 PMmbonnin
01/09/2023, 3:13 PMCarter
01/09/2023, 3:14 PMCarter
01/09/2023, 3:14 PMVampire
01/09/2023, 3:15 PMVampire
01/09/2023, 3:15 PMmbonnin
01/09/2023, 3:15 PMCarter
01/09/2023, 3:16 PMmbonnin
01/09/2023, 3:16 PMproject.tasks.withType(JavaCompile::class.java).configureEach {
options.release.set(11)
}
Carter
01/09/2023, 3:16 PMCarter
01/09/2023, 3:16 PMVampire
01/09/2023, 3:18 PMCarter
01/09/2023, 3:19 PMephemient
01/09/2023, 4:23 PMkotlin
extension which can be used instead of configuring the tasks.
for org.jetbrains.kotlin.jvm
plugin,
kotlin.target.compilations.all {
kotlinOptions.jvmOptions = "11"
}
for org.jetbrains.kotlin.multiplatform
plugin,
kotlin.targets.all {
compilations.all {
(kotlinOptions as? KotlinJvmOptions)?.jvmOptions = "11"
}
}
Carter
01/09/2023, 4:24 PMephemient
01/09/2023, 4:24 PMephemient
01/09/2023, 4:25 PMfreeCompilerArgs
is being deprecatedtapchicoma
01/09/2023, 4:28 PMLast year, it was very problematic because there weren’t Apple Silicon compatible toolchains for Java 11 but there were for Java 17.SDKMAN should provide such toolchains for Mac silicon and then Gradle will auto detect them. With Gradle 7.6 probably this plugin will auto-provision toolchains for Apple silicon.
ephemient
01/09/2023, 4:29 PMCarter
01/09/2023, 4:31 PM