0Pricing
Java Academy · Lesson

Gradle Basics

build.gradle and tasks.

Gradle Basics is a free Java Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Gradle Basics

Gradle is a flexible build tool that uses a programmable build script instead of static XML. Builds are modeled as a graph of tasks, and the script is written in Groovy or Kotlin DSL. This lesson covers the essentials.

The Build Script

Configuration lives in build.gradle (Groovy) or build.gradle.kts (Kotlin). It is real code, so you can use logic, variables, and functions — far more flexible than Maven's XML.

Applying Plugins

Capabilities come from plugins, applied in a plugins block. The java plugin adds compilation, testing, and the standard source layout (the same src/main/java as Maven).

plugins {
    id 'java'
    id 'application'
}

Declaring Repositories

Tell Gradle where to fetch dependencies in a repositories block. mavenCentral() is the usual choice and uses the same artifacts as Maven.

repositories {
    mavenCentral()
}

Dependencies and Configurations

Dependencies are added under named configurations that mirror Maven scopes: implementation, api, testImplementation, runtimeOnly, and compileOnly.

dependencies {
    implementation 'com.google.guava:guava:33.0.0-jre'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

implementation vs api

A key Gradle distinction:

  • implementation — the dependency is hidden from consumers of your library (faster recompiles).
  • api — the dependency leaks onto the compile classpath of consumers.

Prefer implementation unless the type appears in your public API.

Tasks

Everything Gradle does is a task: compileJava, test, jar, build. Tasks declare dependencies on each other, forming a directed acyclic graph that Gradle executes in order.

Running Tasks

Invoke tasks via the wrapper: ./gradlew build, ./gradlew test, ./gradlew run. The wrapper pins the Gradle version per project so everyone builds identically.

Defining a Custom Task

You can register your own tasks. This Groovy DSL task prints a message when run with ./gradlew hello.

tasks.register('hello') {
    doLast {
        println 'Hello from Gradle!'
    }
}

Incremental Builds and Caching

Gradle tracks each task's inputs and outputs. If nothing changed, the task is marked UP-TO-DATE and skipped. The build cache can even reuse outputs across machines, making repeated builds very fast.

The Application Plugin

The application plugin adds a run task and packaging for executable apps. You point it at your main class so ./gradlew run launches the program.

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

Quick Check

Test your understanding of Gradle basics.

Recap

You learned Gradle fundamentals:

  • Builds are configured by a programmable build.gradle(.kts) script.
  • Plugins add capabilities; java and application are common.
  • Dependencies use configurations like implementation, api, testImplementation.
  • Work is modeled as a graph of tasks run via ./gradlew.
  • Incremental builds and the build cache skip unchanged work.

Frequently asked questions

Is the “Gradle Basics” lesson free?

Yes — the full text of “Gradle Basics” is free to read here on the web, and the Java Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “Gradle Basics”?

build.gradle and tasks. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Gradle Basics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Maven Project Structure
  2. Maven Plugins and Goals
  3. Gradle Basics
  4. Choosing a Build Tool
← Back to Java Academy