Gradle says the clean task does not exist
Task 'clean' not found in root projectShort answer
The clean task is not built into every Gradle build. The Base Plugin adds it, and it deletes the build directory. If your build script applies no plugin that brings in base, or the task exists only in a subproject, Gradle cannot find it. Apply the base plugin, or call the task with its project path.
Fix it fast
1Find out which cause you have
Ask Gradle where a task named clean is registered. If nothing is listed, no plugin supplies it; if a subproject path is listed, call that path.
./gradlew help --task clean2Match what you see, then jump to its fix
What does the error look like?
Task 'clean' not found in root projectTask 'clean' not found in root project 'my-app'.
Cause 1 of 2
No plugin that provides clean is applied
1Check
The Base Plugin provides clean as a Delete task for the build directory. A bare build script with no plugins has no such task.
./gradlew tasks --all2Fix
Apply the base plugin in the build file of the project that needs it.
// build.gradle.kts
plugins {
base
}3Verify
Run the task, then confirm the build folder is gone.
./gradlew cleanConfirmed by docs.gradle.org
Cause 2 of 2
clean exists only in a subproject
1Check
In a multi-project build, a task name can be run with a project path. The help output shows every full path where the task is registered.
./gradlew help --task clean2Fix
Call the task with its project path from the root, or run the wrapper from inside the subproject directory and leave the project name out.
./gradlew :app:clean
../gradlew clean # run from inside the app directory3Verify
The task runs without the not-found message.
./gradlew :app:cleanConfirmed by docs.gradle.org
How do I stop it coming back?
- Apply the plugin that matches the project type in each build file instead of relying on another file.
- Use gradlew tasks --all after adding a plugin to see what it registered.
- Run the wrapper from the project root so the task resolves against the right project.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
Gradle clean or build cannot delete the build directory
Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
Gradle could not remove a folder because another process still holds a file in it.
3 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile apps
Android Studio cannot pair the phone over Wi-Fi
The Pair devices over Wi-Fi dialog lists no device
Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.
4 causes, each with a fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fix