The new Gradle instructions from the Kotlin 1.8.0 ...
# gradle
d
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
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
Thanks. If it's an order-of-operations issue, why does it work when I replace
tasks.named
with
tasks.withType
?
e
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
Thanks! I'll look into how to setup convention plugins