leandro
06/21/2023, 12:31 PMJavier
06/21/2023, 1:04 PMLeon Linhart
06/21/2023, 1:35 PMtargets.configureEach {
compilations.configureEach {
compilerOptions.options.apiVersion.set(KotlinVersion.KOTLIN_1_8)
compilerOptions.options.languageVersion.set(KotlinVersion.KOTLIN_1_8)
compilerOptions.options.freeCompilerArgs.add("foo")
}
}leandro
06/21/2023, 5:18 PMJavier
06/21/2023, 5:39 PMJavier
06/21/2023, 5:40 PMleandro
06/21/2023, 6:45 PMtasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>() {
...
}Javier
06/21/2023, 7:08 PMJavier
06/21/2023, 7:09 PMJavier
06/21/2023, 7:10 PMcompilerOptions to the kotlin dsl
kotlin {
compilerOptions {
...
}
}
But maybe it will be on 1.9 or 2.0? Or maybe I am drunk cc @tapchicomaLeon Linhart
06/21/2023, 7:17 PMcompilerOptions DSL is used in my example above. It is not available on the top-level kotlin extension and I don't know if there are any plans to change that.
Don't use org.jetbrains.kotlin.gradle.tasks.KotlinCompile as this class is only used for JVM targets. If you want to configure the compile tasks directly use org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile instead. However, there is no practical difference between my approach and this one.Javier
06/21/2023, 7:17 PMas this class is only used for JVM targetsAre you sure about that? I think that is not correct
Leon Linhart
06/21/2023, 7:21 PMAre you sure about that?Yes. I don't have a source to cite at hand but it's obvious when you look at the source code. Compare, for example,
Kotlin2JsCompile.Javier
06/21/2023, 7:26 PMtapchicoma
06/21/2023, 9:14 PMkotlin.compilerOptions { .. } was added in 1.9.0 for Kotlin/JVM and Kotlin/Android plugins only. Kotlin/MPP should be added in 1.9.20 releaseleandro
06/22/2023, 8:14 AMKotlin/MPP should be added in 1.9.20 releaseDoes that mean I can do something like starting from 1.9.20:
extensions.configure<KotlinMultiplatformExtension> {
compilerOptions {
freeCompilerArgs += listOf()
}
}
and is this better than configuring with tasks.withType?tapchicoma
06/22/2023, 8:20 AMJavier
06/22/2023, 10:09 AMextensions.configure<KotlinProjectExtension> {
compilerOptions {
freeCompilerArgs += listOf()
}
}
so you can reuse the same configuration in any Kotlin project, not only KMPleandro
06/22/2023, 10:31 AMextensions.configure<KotlinMultiplatformExtension>, on my KotlinAndroid convention I get as extensions.configure<KotlinAndroidProjectExtension>. I then share a configuration that receives extension: KotlinProjectExtension as supertypeefemoney
06/22/2023, 5:52 PMIf you want to configure the compile tasks directly usePlease dont, the DSL task isinsteadorg.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
KotlinCompilationTask .
Better still don’t use the task at all (from 1.9.20, use compilerOptions directly from the kotlin extension)Leon Linhart
06/22/2023, 8:07 PMKotlinCompilationTask was added alongside the compilerOptions DSL and I missed it. Thanks for pointing this out.Leon Linhart
06/22/2023, 8:08 PM