tapchicoma
09/12/2023, 3:17 PMkotlin {
compilerOptions {
// Project-level common compiler options that are used as defaults for all targets
allWarningsAsErrors.set(true)
}
// Target-level compiler options
jvm {
compilerOptions {
// JVM compiler options that are used as defaults for all compilations in this target
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
}
js {
compilerOptions {
// JS compiler options that are used as defaults for all compilations in this target
moduleKind.set(org.jetbrains.kotlin.gradle.dsl.JsModuleKind.AMD)
}
}
linuxX64 {
compilerOptions {
// Native compiler options that are used as defaults for all compilations in this target
languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0) // Overrides default version ‘1.9’
}
}
iosArm64 {
compilerOptions {
// Native compiler options that are used as defaults for all compilations in this target
allWarningsAsErrors.set(false) // Overrides project-level configuration
}
}
}
And related languageSettings
values are also synced with related compilation task compilerOptions
. Please give it a try and provide feedback 🙂mbonnin
09/13/2023, 1:14 PMcompilerOption
is not available on KotlinProjectExtension
, only on KotlinJvmProjectExtension
and KotlinMultiplatformExtension
so to configure the common options in a convention plugin, I have to do this:
val kotlin = project.kotlinExtension
when (kotlin) {
is KotlinJvmProjectExtension -> kotlin.compilerOptions {
configureCommonOptions()
}
is KotlinMultiplatformExtension -> kotlin.compilerOptions {
configureCommonOptions()
}
}
Or is there a way to do it in one go in a project that applies both the KMP and JVM plugins?
project.kotlinExtension.compilerOptions.configureCommonOptions()
?tapchicoma
09/13/2023, 1:18 PMKotlinTopLevelExtension
interfacembonnin
09/13/2023, 1:46 PMprivate fun KotlinProjectExtension.forEachCompilerOptions(block: KotlinCommonCompilerOptions.() -> Unit) {
when (this) {
is KotlinJvmProjectExtension -> compilerOptions.block()
is KotlinMultiplatformExtension -> {
targets.all {
compilerOptions.block()
}
}
else -> error("Unknown kotlin extension $this")
}
}
But now I realize this is probably wrong as well? Should I go into the compilations
compilerOptions? Or does target.compilerOption
is going to be applied to each compilation
?tapchicoma
09/13/2023, 1:56 PMkotlin.compilerOptions
used as a convention values for all targets, target.compilerOptions
used a convention value for all compilations in this target and kotlinCompilation.compilerOptions === kotlinCompileTask.compilerOptions
tapchicoma
09/13/2023, 1:57 PMkotlin.compilerOptions
should also configure Android target as well