Skip to content
Latchkey

gradle build: The Full Build Lifecycle Task

gradle build is an aggregate lifecycle task that depends on assemble and check, so it both produces artifacts and runs verification.

build is the task most CI jobs invoke. Knowing it is just assemble plus check explains why it compiles, packages, and runs tests in one shot.

What it does

The build task is a lifecycle task added by the base plugin. It has no actions of its own; it depends on assemble (produce the outputs, e.g. the jar) and check (run all verification, including test). So ./gradlew build compiles, packages, and tests in dependency order.

Common usage

Terminal
./gradlew build
./gradlew build -x test          # build but skip tests
./gradlew clean build            # fresh build
./gradlew build --scan           # build with a build scan link

Flags

FlagWhat it does
-x <task>Exclude a task, e.g. -x test to skip tests
--scanPublish a build scan for diagnostics
--console=plainDisable the rich console (cleaner CI logs)
-S / --full-stacktracePrint full stacktraces on failure
--warning-mode allSurface deprecation warnings

In CI

Run ./gradlew --no-daemon build on ephemeral runners so no daemon lingers, and cache ~/.gradle/caches and ~/.gradle/wrapper between jobs. Add --build-cache to reuse task outputs. --console=plain keeps the log readable in CI.

Common errors in CI

"Execution failed for task ':test'" with "There were failing tests" means check failed, not the packaging; the report is under build/reports/tests. "Task 'build' not found in root project" in a multi-project build means you must qualify it, e.g. :app:build. "Could not resolve all files for configuration ':compileClasspath'" is a dependency/network problem, not a build logic error.

Related guides

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