Add behavior to clean task via Kotlin DSL

I want to delete some non standard files when the clean task runs. How can I do this using the Kotlin DSL?

I found the Manipulating existing tasks section in the user guide. But that shows manipulating the custom “hello” task defined in the same script. When I try to do that for clean:

// Kotlin DSL
clean {
    doFirst {
        val file = File("/tmp/gradleExtraClean/foo.txt")
        file.delete()
    }
}

I get an Unresolved reference: clean error. And I’m not sure to get a reference to the clean task. Or if my approach is completely wrong.

I did figure this out (but forgot to update this post at the time in case someone else finds in via a search)

// Kotlin DSL
tasks.clean {
    doFirst {
        val file = File("/tmp/gradleExtraClean/foo.txt")
        file.delete()
    }
}