gradle-clean
Remove generated build files
TLDR
Clean the build directory
Clean and then build the project
Clean a specific subproject in a multi-project build
Clean with more detailed logging
SYNOPSIS
gradle clean [options] [projects ...]
PARAMETERS
--help, -h
Prints help and usage for the clean task.
--dry-run
Simulates execution without deleting files.
--info, -i
Enables info-level logging during cleanup.
--debug
Provides verbose debug output.
-P
Passes project properties to influence clean behavior.
--no-daemon
Disables Gradle daemon for one-off runs.
--parallel
Enables parallel execution if multi-project.
DESCRIPTION
The gradle clean command (often invoked as gradle-clean via alias or script) runs the default 'clean' task in Gradle, an open-source build automation tool for Java, Kotlin, Android, and multi-language projects. It recursively deletes the build directory, including compiled classes, JAR files, test reports, caches, and other generated outputs from prior builds.
This prevents build inconsistencies caused by stale artifacts, ensuring reproducible builds. On Linux, use the Gradle Wrapper ./gradlew clean from the project root for version consistency without global installation. The task is lifecycle-aware, respecting project structure and plugins like Java or Android.
Common in development, pre-commit hooks, and CI/CD pipelines (e.g., Jenkins, GitHub Actions). Execution is fast for small projects but can be time-intensive for large monorepos due to deep deletion. Always idempotent: running multiple times has the same effect.
Integrates with Gradle's daemon for efficiency, reducing JVM startup overhead on repeated runs.
CAVEATS
Irreversibly deletes files; backup important artifacts. Requires Java JDK. Slow on large projects with deep caches. Wrapper (gradlew) preferred over global gradle.
EXAMPLE USAGE
./gradlew clean -- Single project.
gradle :app:clean :lib:clean -- Specific subprojects.
EXIT CODES
0: Success.
1+: Failure (e.g., permission denied, missing dirs).
HISTORY
Gradle debuted in 2007 by Hans Dockter; 'clean' task core since v0.8 (2008). Evolved with v1.0 (2012) milestone for stability, now at v8+ with faster incremental cleans via configuration cache.


