Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

What Is Gradle?

Learn what Gradle is, what a build tool does, how tasks form a graph, and why Gradle is the standard for Java, Kotlin and Android projects.

Every real program needs more than a compiler. Someone has to download libraries, compile sources in the right order, run tests, package the result into a JAR or an app bundle, and sometimes publish it. Doing this by hand is slow and error-prone, so teams automate it with a build tool. Gradle is one of the most widely used build tools in the world: it builds almost every Android app, a large share of Java and Kotlin servers, and it is the tool behind many open source libraries.

This course teaches Gradle from the first command to multi-project builds, plugins, testing and publishing. A note on honesty before we start: the site's code runners cannot run the Gradle program itself (it needs a JVM, a network and a project folder on disk). So the real Gradle files in these lessons are read-only, and wherever possible we add a small runnable stand-in in Java or Kotlin that demonstrates the idea underneath, such as how a task graph is ordered. Stand-ins are always labelled; they are not Gradle.

What a build tool does

A build is a set of steps that turns source files into something you can run or ship. A typical Java build looks like this:

  1. Resolve and download the libraries your code uses.
  2. Compile the main sources.
  3. Compile and run the tests.
  4. Package the compiled classes into a JAR.
  5. Optionally publish the JAR to a repository.

Each step needs the previous one. A build tool knows these relationships, runs the steps in a valid order, and skips steps whose results are already up to date.

Gradle in one picture

Gradle models a build as a set of tasks connected by dependencies. You ask for one task, for example build, and Gradle works out every task that must run first.

flowchart LR
  A["compileJava"] --> B["classes"]
  B --> C["jar"]
  B --> D["compileTestJava"]
  D --> E["test"]
  C --> F["assemble"]
  E --> G["check"]
  F --> H["build"]
  G --> H

A simplified task graph for a Java project. Asking for build runs every task on the way.

Three ideas make Gradle special:

  • A directed acyclic graph of tasks. Gradle builds the whole graph before it runs anything, so it can order, skip and even parallelize tasks.
  • Incremental builds. A task declares its inputs and outputs. If nothing changed since the last run, Gradle marks it UP-TO-DATE and skips it.
  • A programmable build file. Build logic is written in a real language: Groovy or Kotlin. You are not limited to a fixed list of options in an XML file.

A first look at a real build file

Here is a complete, minimal Gradle build for a Java application, written in the Kotlin DSL (build.gradle.kts). It is shown read-only because Gradle is not installed on this site.

Kotlin
plugins {
    application
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.google.guava:guava:33.4.0-jre")
    testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
}

application {
    mainClass = "com.example.App"
}

The plugins block adds the Java application plugin, which brings the tasks compileJava, test, jar, run and more. repositories says where to download libraries from. dependencies lists them. You will learn each block in the chapters ahead.

How Gradle compares with Ant and Maven

Tool Build file Style Strength
Ant XML You script every step Flexible, but you write everything yourself
Maven XML (pom.xml) Fixed lifecycle, conventions Very predictable; huge ecosystem
Gradle Groovy or Kotlin Task graph plus conventions Fast incremental builds, build cache, flexible

Gradle keeps Maven's idea of "convention over configuration" (a standard folder layout, src/main/java) but lets you change or extend anything with code. It can also use Maven repositories, so every library on Maven Central works.

A runnable stand-in: ordering tasks

The stand-in below is not Gradle. It shows the core idea: tasks declare what they depend on, and a tool derives a valid run order with a depth-first walk. Press Run and watch the order for build.

Java Stand-in: derive a run order from task dependencies

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Real Gradle does the same walk, but it also runs tasks in parallel when it is safe and skips tasks that are up to date.

A runnable stand-in: skipping work

The second stand-in imitates an incremental build. A "task" remembers a fingerprint of its input; if the input did not change, it prints UP-TO-DATE.

Java Stand-in: UP-TO-DATE checks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Real Gradle fingerprints file contents, task properties and the classpath, and stores the result on disk. You will meet this again in Inputs, Outputs and Up-to-date Checks.

Where Gradle is used

  • Android: the official Android Gradle Plugin is built on Gradle.
  • JVM languages: Java, Kotlin, Scala and Groovy all have first-class support.
  • Native and other: C++, Swift and generic task automation also work.
  • Large builds: Gradle's build cache and parallel execution shine in big, multi-project repositories.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Gradle build before it runs any task?

    Gradle first configures the build and constructs the task graph, then executes only the tasks needed for the requested goal.
  2. 2. What does the status UP-TO-DATE mean next to a task?

    Gradle compares fingerprints of a task's inputs and outputs with the previous run. If they match, it skips the work.
  3. 3. Which languages can you write Gradle build scripts in?

    Gradle supports the Groovy DSL (build.gradle) and the Kotlin DSL (build.gradle.kts).
  4. 4. What is the role of the plugins block in a build file?

    Plugins contribute tasks, conventions and configuration. Dependencies are declared in the dependencies block.

Summary

  • A build tool automates compiling, testing, packaging and publishing.
  • Gradle models a build as a graph of tasks and runs only what is needed.
  • Incremental builds skip tasks whose inputs and outputs have not changed.
  • Build files are real code, in Groovy or Kotlin.
  • Gradle is the standard tool for Android and very common for Java and Kotlin.
  • In this course, real Gradle code is read-only and every runnable example is a labelled stand-in.

Next: Installing Gradle and the Wrapper