Which is the "proper"/best-practice way below? ``...
# gradle
g
Which is the "proper"/best-practice way below?
Copy code
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions.useK2 = true // 1
    compilerOptions {
        useK2.set(true)        // 2
    }
}
1
j
2, indeed 1 is not working any more with 1.8.0 I think (for sure with 1.8.255-SNAPSHOT)
g
Oh, very good to know, as I am using 1.8 and Gradle 8 -- ty!
j
Are you not getting a deprecated warning with 1?
g
I was in the process of potentially transitioning from a setup like this:
Copy code
tasks.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)
I think I may just keep the giant
COMPILER_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:
Copy code
"-Xjsr305=strict",
"-Xcontext-receivers",
"-Xextended-compiler-checks",
"-Xuse-fast-jar-file-system",
"-Xuse-fir-extended-checkers"
(Maybe they already exist and I dunno about them)
v
Which 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. 😉