How do I extend gradle’s clean task to delete a file?

You just need to use double quotes. Also, drop the << and use doFirst instead if you are planning to do the deletion during execution. Something like this:

clean.doFirst {
    delete "${rootDir}/api-library/auto-generated-classes/"
    println "${rootDir}/api-library/auto-generated-classes/"
}

Gradle build scripts are written in Groovy DSL. In Groovy you need to use double quotes for string interpolation (when you are using ${} as placeholders). Take a look at here.

Leave a Comment