Gavin Ray
12/20/2022, 6:01 PMtasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.useK2 = true // 1
compilerOptions {
useK2.set(true) // 2
}
}Javier
12/20/2022, 6:18 PMGavin Ray
12/20/2022, 6:21 PMJavier
12/20/2022, 6:22 PMGavin Ray
12/20/2022, 6:29 PMtasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions.javaParameters = true
kotlinOptions.freeCompilerArgs = Constants.KOTLIN_COMPILER_ARGS
}
val KOTLIN_COMPILER_ARGS = listOf(
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.Experimental",
"-Xenhance-type-parameter-types-to-def-not-null",
// ...
)
Currently using Gradle 8.0 Milestone-2 and Kotlin 1.8.0-RC
(About to upgrade to Gradle 8-M5)Gavin Ray
12/20/2022, 6:31 PMCOMPILER_ARGS block since it's uniform though
Separately enabling k2, incremental etc would mean pulling those args out into different places but still having this big block
It'd be nice to have Gradle variables for things like these:
"-Xjsr305=strict",
"-Xcontext-receivers",
"-Xextended-compiler-checks",
"-Xuse-fast-jar-file-system",
"-Xuse-fir-extended-checkers"Gavin Ray
12/20/2022, 6:31 PMVampire
12/20/2022, 8:54 PMWhich is the "proper"/best-practice way below?Neither. Because you use
tasks.withType<...> { ... } which eagerly realizes all tasks of that type unnecessarily, use tasks.withType<...>().configureEach { ... } instead. 😉