tseisel
01/30/2022, 12:56 PMtasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xno-param-assertions",
"-Xno-call-assertions",
"-Xno-receiver-assertions"
)
}
}
but it's applied to all build variants, which is not what I want.
The kotlin.android
Gradle plugin creates compilation tasks (compileDebugKotlin
, compileReleaseUnitTestKotlin
, etc) for each source set, but it seems there is no way to configure their kotlinOptions
individually.Paul Woitaschek
01/30/2022, 2:20 PMtseisel
01/30/2022, 6:58 PMafterEvaluate
. It's because compile*Kotlin tasks are created lazily based on the created variants.
Because relying on afterEvaluate
is flagged as a bad practice by Gradle, I'd expect the kotlin Android plugin to define an alternative configuration DSL.
Maybe it hasn't leveraged the new extension DSL introduced in Android gradle Plugin v7.0.0 ?Vampire
01/31/2022, 3:39 PMafterEvaluate
or you are doing something wrong.
Paul did probably not mean to use tasks.named("compileDebugKotlin")
where that might be true, but more something like
tasks.withType<KotlinCompile>().matching { it.name == "compileDebugKotlin" }.configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xno-param-assertions",
"-Xno-call-assertions",
"-Xno-receiver-assertions"
)
}
}