Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle says the clean task does not exist

ErrorTask 'clean' not found in root project

Short 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.

  • Applies to Gradle 8.x and 9.x, JDK 17 and 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 clean
  2. 2Match what you see, then jump to its fix

    1. 1help --task clean finds nothing, and the build file has an empty or missing plugins blockNo plugin that provides clean is appliedFix
    2. 2help --task clean lists paths like :app:clean but not :cleanclean exists only in a subprojectFix

What does the error look like?

  • Task 'clean' not found in root project
  • Task '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 --all

2Fix

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 clean

Confirmed by docs.gradle.org

Did this fix it?

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 clean

2Fix

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 directory

3Verify

The task runs without the not-found message.

./gradlew :app:clean

Confirmed by docs.gradle.org

Did this fix it?

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 fix

Mobile 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.