gradle
Build and automate software projects
TLDR
Compile a package
Exclude test task
Run in offline mode to prevent Gradle from accessing the network during builds
Clear the build directory
Build an Android Package (APK) in release mode
List the main tasks
List all the tasks
SYNOPSIS
gradle [option...] [task...]
Examples:
gradle build
gradle clean test
gradle --info assemble
PARAMETERS
--version
Displays Gradle version information.
--help
Shows a help message for the command-line options.
--build-file
Specifies the build file to use (e.g., build.gradle).
-b
Shorthand for --build-file.
--project-dir
Specifies the start directory for Gradle.
-p
Shorthand for --project-dir.
--daemon
Uses the Gradle Daemon for faster build execution. This is the default behavior.
--no-daemon
Do not use the Gradle Daemon. A new JVM process will be started for the build.
--refresh-dependencies
Refreshes all external dependencies.
--stacktrace
Prints the stacktrace on error.
--info
Sets the logging level to INFO.
--debug
Sets the logging level to DEBUG.
--offline
Works offline, without accessing network resources.
--parallel
Allows tasks to be executed in parallel.
--configure-on-demand
Configures projects only as needed by the requested tasks.
DESCRIPTION
The gradle command executes Gradle, an open-source build automation tool that combines the best features of Apache Ant and Apache Maven. It is renowned for its flexibility, performance, and its use of a Groovy or Kotlin-based Domain Specific Language (DSL) for defining build scripts.
Gradle is widely used for building diverse projects, including Java, Android, C/C++, and web applications. Key features include incremental builds, a build cache, and the Gradle Daemon, all contributing to faster build times. Its plugin-driven architecture allows for extensive customization and integration with various development ecosystems, making it a highly adaptable solution for complex software development workflows.
CAVEATS
The flexibility and power of Gradle come with a potential learning curve, especially concerning its DSL and custom task definitions. For large projects, build scripts can become complex if not well-structured. The Gradle Daemon can consume significant memory, although it greatly improves subsequent build times.
BUILD SCRIPTS
Gradle build logic is defined in files named build.gradle (Groovy) or build.gradle.kts (Kotlin). These scripts declare project dependencies, define tasks, and apply plugins to extend functionality.
PLUGINS
Gradle's core functionality is extended via plugins. Plugins encapsulate reusable build logic for common scenarios, such as compiling Java code, packaging Android applications, or publishing libraries.
GRADLE DAEMON
The Gradle Daemon is a long-lived background process that keeps a JVM instance running. This significantly reduces startup time for subsequent builds, as the JVM doesn't need to be initialized from scratch and project structure can be cached.
GRADLE WRAPPER
The Gradle Wrapper (gradlew on Linux/macOS, gradlew.bat on Windows) is a script that ensures a consistent Gradle version is used across different development environments, automatically downloading it if necessary. This promotes reproducible builds.
HISTORY
Gradle was first released in 2007. It gained significant traction, particularly after becoming the official build system for Android development in 2013. Initially using a Groovy DSL, Gradle introduced support for a Kotlin DSL in 2017, providing a more type-safe and IDE-friendly scripting experience. Continuous development has focused on performance improvements, including the introduction of the Gradle Daemon, build cache, and configuration cache.