Q:

is there any way to clean all projects in gradle 6.0.1

I want to clean all project of gradle,now I using this task in root project build.gradle:
task clean {
    subprojects.each {
        it.afterEvaluate {
            def cleanTask = it.tasks.findByName('clean')
            if (cleanTask) {
                dependsOn(cleanTask)
            }
        }
    }
}

it give me tips this clean task already exists,is there other way to do this task?I do not want to write many code like :
./gradlew clean projectA
./gradlew clean projectB
./gradlew clean projectC

Now I have more than 30 project. 

A:

There's a feature in Gradle where:

If you call a task on the root project 
And the root project does not contain that task 
A "proxy" task will be created in the root project 
The "proxy" task will invoke any tasks with the same name in its subprojects 

So usually, your subprojects will contain a "clean" task and your root project will not.  So invoking "clean" on the root project will actually invoke "clean" on all the subprojects.  I think this is the behavior you want?  
If this is not occurring, it's likely you've created a "clean" task in your root project with different behavior (perhaps you applied the "base" plugin to the root project?).  I suggest you remove the "clean" task from the root project 

