Gradle 8.4, unable to create task based on code in documentation

I tried following the steps here: Part 2: Running Gradle Tasks

tasks.register("copyTask",Copy) {
    from("source")
    into("target")
    include("*.war")
}

But the IDE prompted me with wrong information.

This example and the following are indeed wrong.
They are showing the Groovy DSL variant.
When the Kotlin DSL became the default, Part 1 was adapted properly, so you have a Kotlin DSL build script.
But the further code examples were not changed accordingly.
You should report a bug about this documentation issue.

For that specific snippet the correct version is

tasks.register<Copy>("copyTask") {
    from("source")
    into("target")
    include("*.war")
}

or

val copyTask by tasks.registering(Copy::class) {
    from("source")
    into("target")
    include("*.war")
}

OK, I’ll report the issue, thank you.

1 Like