Skip to content
Latchkey

gradle clean: Usage, Options & Common CI Errors

Delete build/ - useful, but not a substitute for fixing cache issues.

clean is the Gradle task (from the base plugin) that deletes the project’s build directory (build/). It removes compiled classes, reports, and artifacts so the next build starts from scratch.

What it does

clean deletes the directory referenced by layout.buildDirectory (default build/). It does not clear the Gradle build cache or ~/.gradle - only the per-project outputs. Chaining clean build forces a full rebuild of that project.

Common usage

Terminal
./gradlew clean
./gradlew clean build
./gradlew clean test --rerun-tasks

Common error in CI (and the fix)

Symptom: a team adds clean to every CI run to "fix" flaky incremental builds, and build times balloon. Cause: clean discards Gradle’s incremental and up-to-date state, forcing full recompiles. Fix: only clean when build outputs are genuinely corrupt; for correctness issues prefer --rerun-tasks or fixing the task’s declared inputs/outputs, and rely on the build cache instead of blanket cleans.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →