https://kotlinlang.org logo
#gradle
Title
d

Dan Rusu

12/29/2022, 6:18 PM
The new Gradle instructions from the Kotlin 1.8.0 release don't work when trying to use the new compiler options: https://kotlinlang.org/docs/whatsnew18.html#exposing-kotlin-compiler-options-as-gradle-lazy-properties This line:
tasks.named("compileKotlin", org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile::class.java) {
generates this error when refreshing Gradle:
Task with name 'compileKotlin' not found in project...
I was able to get around it by switching that line with this:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile::class.java) {
Am I missing something else or are the new instructions incorrect?
e

ephemient

12/29/2022, 6:30 PM
don't use
allProjects
if you want to centralize configuration, the recommended path is to write convention plugins
you are seeing this because your block is running before the plugin is applied
d

Dan Rusu

12/29/2022, 6:33 PM
Thanks. If it's an order-of-operations issue, why does it work when I replace
tasks.named
with
tasks.withType
?
e

ephemient

12/29/2022, 6:34 PM
because that works even when the task doesn't exist yet
it applies to any existing and future tasks with type, whereas named adds configuration to an existing task only
speaking of which, you should also avoid using
withType(action)
for lazy configuration reasons (it's not, for historical Gradle reasons)
.withType().configureEach(action)
will be lazy if you need
d

Dan Rusu

12/29/2022, 6:38 PM
Thanks! I'll look into how to setup convention plugins
15 Views