Gradle automates building, testing, and deployment of software from information in build scripts.

gradle basic 1

Core concepts

Gradle builds are defined in terms of projects and tasks, configured using build scripts written in Groovy or Kotlin.

Concept What It Means

Build

The process and environment for producing outputs. A build includes one or more projects and their build scripts.

Project

A piece of software that can be built, such as an application or library. A build may have a single root project or multiple subprojects.

Task

A basic unit of work, like compiling code or running tests. Tasks are declared in build scripts or added by plugins.

Build Script

A configuration file (build.gradle(.kts)) that defines tasks, dependencies, and other instructions that tell Gradle how to build a project.

Plugin

Used to extend Gradle’s capabilities (like the Java plugin). Plugins often add tasks and conventions to projects.

Dependency

External or internal resources required by a project. Gradle automatically resolves these during the build.

Project structure

Many developers will interact with Gradle for the first time through an existing project.

The presence of the gradlew and gradlew.bat files in the root directory of a project is a clear indicator that Gradle is used.

A Gradle project will look similar to the following:

project
├── gradle                          (1)
├── gradlew                             (2)
├── gradlew.bat                         (2)
├── settings.gradle(.kts)           (3)
├── subproject-a
│   ├── build.gradle(.kts)              (4)
│   └── src/                        (5)
└── subproject-b
    ├── build.gradle(.kts)              (4)
    └── src/                        (5)
1 Gradle directory to store wrapper files and more
2 Gradle wrapper scripts - THIS IS A GRADLE PROJECT!
3 Gradle settings file to define a root project name and subprojects
4 Gradle build scripts of the two subprojects - subproject-a and subproject-b
5 Source code and/or additional files for the projects

Invoking Gradle

In the IDE

Gradle is built-in to many IDEs including Android Studio, IntelliJ IDEA, Visual Studio Code, Eclipse, and NetBeans.

Gradle can be automatically invoked when you build, clean, or run your app in the IDE.

gradle ide invocation

Consult the manual for the IDE of your choice to learn more about how Gradle can be used and configured.

On the Command Line

Gradle can be invoked in the command line once installed:

$ gradle build
$ gradle test
$ gradle clean build

Most projects do not use the installed version of Gradle but rather the Gradle Wrapper.

With the Gradle Wrapper

The wrapper is a script that invokes a declared version of Gradle and is the recommended way to execute a Gradle build:

$ ./gradlew build
gradle terminal invocation