LinuxCommandLibrary

gradle

Build and automate software projects

TLDR

Compile a package

$ gradle build
copy

Exclude test task
$ gradle build [[-x|--exclude-task]] test
copy

Run in offline mode to prevent Gradle from accessing the network during builds
$ gradle build --offline
copy

Clear the build directory
$ gradle clean
copy

Build an Android Package (APK) in release mode
$ gradle assembleRelease
copy

List the main tasks
$ gradle tasks
copy

List all the tasks
$ gradle tasks --all
copy

SYNOPSIS

gradle [options] [--] [tasks]

PARAMETERS

-b, --build-file <file>
    Specify the build file (default: build.gradle or build.gradle.kts)

-c, --init-script <file>
    Run the init script before the build script

-D <property>=<value>
    Set a project property

--daemon
    Run (or re-use) the Gradle daemon

--no-daemon
    Do not run via the daemon

-p, --project-dir <dir>
    Change to the specified project directory

--parallel
    Build projects in parallel

--no-parallel
    Do not build projects in parallel

--offline
    Do not resolve dependencies from the network

-P <property>=<value>
    Set a project property (alternative to -D)

--rerun-tasks
    Ignore cached task results and re-execute tasks

-s, --stacktrace
    Print stacktrace for all errors

--status
    Display status of Gradle daemons

--stop
    Stop all Gradle daemons

-v, --version
    Print version info

-h, --help
    Show help

DESCRIPTION

Gradle is a powerful, open-source build automation tool primarily designed for Java, but supports multiple languages including Kotlin, Scala, and Android development.

It uses a domain-specific language (DSL) based on Groovy or Kotlin to define build scripts, allowing declarative configuration of dependencies, tasks, and plugins. Unlike traditional tools like Ant or Maven, Gradle models builds as directed acyclic graphs (DAGs) of tasks, enabling efficient incremental builds, parallel execution, and build caching.

Key features include a flexible plugin system, dependency management via repositories like Maven Central, and support for multi-project builds. The Gradle daemon improves performance by reusing the JVM across builds. It's widely used in enterprise environments for its speed and extensibility.

On Linux, Gradle is typically installed via package managers (e.g., apt, yum), SDKMAN, or downloaded as a distribution. Builds are executed via the gradle command, specifying tasks like build, test, or clean. The Gradle Wrapper (gradlew) ensures reproducible builds across environments.

CAVEATS

Requires a JDK (not just JRE); large builds may consume significant memory; daemon can leave processes running if not stopped properly.

GRADLE WRAPPER

Use gradlew (generated script) instead of system-installed Gradle for reproducible, version-specific builds across teams.

DAEMON

Enabled by default for faster builds; monitor with gradle --status and stop with gradle --stop.

HISTORY

First released in 2007 by Hans Dockter as an alternative to Maven, Gradle reached version 1.0 in 2012. It gained popularity with Android Studio adoption around 2013. Current stable versions are in the 8.x series, with ongoing improvements in Kotlin DSL and build performance.

SEE ALSO

mvn(1), ant(1), make(1)

Copied to clipboard