LinuxCommandLibrary

gradle-build

Build a Gradle project

TLDR

Build the project

$ gradle build
copy

Perform a clean build
$ gradle clean build
copy

Build the project while skipping tests
$ gradle build [[-x|--exclude-task]] test
copy

Build with more detailed logging
$ gradle build [[-i|--info]]
copy

SYNOPSIS

gradle [options] build [project-path] [--args]

PARAMETERS

-b, --build-file
    Specifies the build file (default: build.gradle)

-p, --project-dir
    Sets the working project directory

--dry-run
    Runs tasks without executing actions

-q, --quiet
    Log only errors

-i, --info
    Show informative logs

-d, --debug
    Enable debug logging

--stacktrace
    Print full stacktrace on errors

--scan
    Generates a build scan for analysis

-P, --project-prop
    Sets a project property

-D, --system-prop
    Sets a JVM system property

DESCRIPTION

The gradle build command (often invoked as gradle-build in scripted contexts or wrappers) is part of Gradle, an open-source build automation tool primarily for Java, Kotlin, and multi-language projects. It executes the standard build task, which compiles source code, runs unit tests, performs static code analysis, and assembles project artifacts like JARs or WARs into a build/libs directory.

Gradle uses a Groovy- or Kotlin-based DSL in build.gradle or build.gradle.kts files to define tasks, dependencies, and plugins. The build task depends on subtasks like compileJava, test, and jar, ensuring reproducible builds via Gradle's incremental compilation and caching. It's commonly run via the Gradle Wrapper (./gradlew build) to avoid local installation issues, ensuring consistent versions.

Ideal for large-scale projects, it supports parallel execution, dependency management from repositories like Maven Central, and integration with CI/CD tools like Jenkins or GitHub Actions. Output includes success/failure logs with timings, and failures halt the process with stack traces.

CAVEATS

Requires Java JDK (version per Gradle compatibility matrix); needs build.gradle file in current directory; large projects may consume significant memory; Wrapper (gradlew) preferred over global gradle.

COMMON USAGE

./gradlew build (wrapper)
gradle clean build (rebuild from scratch)

EXIT CODES

0: success
1: build failure
2+: other errors

HISTORY

Gradle originated in 2007 by Hans Dockter at Gradle Inc. First public release 0.1 in 2008; v1.0 in 2012 introduced stable APIs. Evolved with Kotlin DSL (2018), build cache (2014), and configuration cache (8.0, 2022). Widely used in Android (official since 2010) and enterprise Java.

SEE ALSO

gradle(1), make(1), mvn(1), ant(1), cmake(1)

Copied to clipboard