Gradle Tutorial
Learn Gradle step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
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.
- Installing Gradle and the Gradle Wrapper Install Gradle on Windows, macOS and Linux, check your JDK, and learn why every project should use the Gradle Wrapper (gradlew) instead of a global install.
- Your First Gradle Build: gradle init and Project Layout Create a Gradle project with gradle init, understand every generated file, and learn the standard src/main and src/test layout and the build output folders.
- The Gradle Build Lifecycle: Initialization, Configuration, Execution Understand Gradle's three build phases, why code in a task body runs later than code in the build script, and how this causes the most common beginner bugs.
- Gradle Command-Line Basics: Tasks, Flags and Logging Learn the Gradle command line: run and chain tasks, exclude tasks with -x, abbreviate names, see more output, run dry runs, and use the daemon and build scans.
Projects and Tasks
- Projects and settings.gradle: Naming and Including Projects Learn how settings.gradle(.kts) defines a Gradle build: rootProject.name, include, project paths, the Project object, and what a build script can see.
- Gradle Tasks: Registering, doFirst, doLast and onlyIf Create Gradle tasks with tasks.register, add actions with doFirst and doLast, group and describe them, skip them with onlyIf, and configure existing tasks.
- Task Dependencies and Ordering: dependsOn, mustRunAfter, finalizedBy Control which Gradle tasks run and in what order with dependsOn, mustRunAfter, shouldRunAfter and finalizedBy, and learn how cycles are detected.
- Inputs, Outputs and Up-to-date Checks in Gradle See how Gradle decides to skip work: declare task inputs and outputs, use @InputFiles and @OutputDirectory, and understand fingerprints and the build cache.
- Custom Task Types: Copy, Exec, Zip and Your Own Classes Use built-in task types such as Copy, Exec, Zip and Delete, then write your own reusable Gradle task class with typed properties and a @TaskAction method.
Build Scripts: Groovy and Kotlin DSL
- Groovy DSL Basics: Reading build.gradle Files Read and write build.gradle with confidence: Groovy syntax for strings, closures, method calls without parentheses, maps, plugins and dependencies blocks.
- Kotlin DSL Basics: build.gradle.kts, Type Safety and Migration Learn the Gradle Kotlin DSL: lambdas with receivers, type-safe accessors, tasks.named and register, and how to translate a Groovy build file to build.gradle.kts.
- Gradle Properties: gradle.properties, -P and Extra Values Configure builds with gradle.properties, -P and -D flags, environment variables and extra properties, and learn the precedence rules and how to keep secrets out of git.
- Lazy Configuration: Providers, Properties and Task Avoidance Understand Gradle's lazy configuration: Provider and Property types, map and flatMap, task configuration avoidance with register, and why it speeds up large builds.
Dependencies and Repositories
- Declaring Dependencies: implementation, api, runtimeOnly and More Declare Gradle dependencies correctly: coordinates, implementation vs api, compileOnly, runtimeOnly, testImplementation, project dependencies and configuration inheritance.
- Repositories and Version Catalogs (libs.versions.toml) Configure Maven Central, Google and private repositories, centralize repositories in settings, and manage versions with a libs.versions.toml version catalog.
- Dependency Resolution and Version Conflicts in Gradle Learn how Gradle resolves transitive dependencies, picks the highest version in a conflict, and how to read dependency trees, dependencyInsight and force or strict versions.
- Constraints, Platforms (BOMs) and Exclusions in Gradle Control transitive dependencies with constraints, import a BOM with platform(), align versions, exclude unwanted modules and use capabilities, with runnable stand-ins.
Plugins
- Gradle Plugins: What They Are and How to Apply Them Learn what Gradle plugins do, how the plugins block works, the difference between core, community and local plugins, plugin IDs, versions, apply false and the Plugin Portal.
- The Java, Java Library and Application Plugins Learn what the Gradle java, java-library and application plugins add: source sets, task lifecycle, api versus implementation, toolchains, jar and run tasks.
- Writing Custom Gradle Plugins and Convention Plugins Learn to write Gradle plugins: script plugins, buildSrc, precompiled convention plugins, binary plugins in Kotlin, extensions, task registration and testing them.
Multi-project Builds
- Gradle Multi-project Builds: settings.gradle and Subprojects Learn how Gradle multi-project builds work: settings.gradle.kts, include, project paths, directory layout, shared configuration, allprojects versus convention plugins.
- Project Dependencies in Multi-project Gradle Builds Learn how subprojects depend on each other in Gradle: project() dependencies, build order, api versus implementation, test fixtures, cycles and typesafe project accessors.
- Composite Builds, Version Catalogs and BOMs in Gradle Learn includeBuild composite builds, dependency substitution, libs.versions.toml version catalogs, bundles, plugin aliases and platform (BOM) dependencies in Gradle.
Testing and Publishing
- Testing with JUnit 5 in Gradle: the test Task Learn how Gradle runs tests: useJUnitPlatform, test dependencies, filtering with --tests, logging, reports, system properties, parallel forks and failing the build.
- Gradle Test Suites, Integration Tests and JaCoCo Coverage Learn the JVM Test Suite plugin for integration tests, separate source sets, check lifecycle wiring, JaCoCo coverage reports and verification rules, and flaky-test strategies.
- Publishing Libraries with Gradle: maven-publish and POM Learn to publish a Java library with Gradle's maven-publish plugin: publications, POM metadata, sources and javadoc jars, repositories, credentials, signing and Maven Central basics.
- Gradle Versioning, Fat Jars, Distributions and Releases Learn how to version Gradle builds with SemVer and snapshots, set jar manifests, build fat jars, application distributions, reproducible archives and a safe release flow.
Performance and Migration
- Gradle Incremental Builds, Up-to-date Checks and Build Cache Understand how Gradle skips work: task inputs and outputs, up-to-date checks, @Input annotations, the local and remote build cache, cacheability and diagnosing cache misses.
- Gradle Daemon, Parallel Builds and the Configuration Cache Speed up Gradle builds: the daemon, gradle.properties JVM settings, parallel execution, the configuration cache, build scans and profiling, and a checklist for slow builds.
- Migrating from Maven or Ant to Gradle A practical guide to migrating from Maven or Ant to Gradle: gradle init, mapping POM elements, scope to configuration table, plugins, profiles, multi-module builds and validation.
- Migrating Groovy to Kotlin DSL and Upgrading Gradle Safely Convert Groovy build scripts to the Kotlin DSL file by file, learn the syntax differences, then upgrade Gradle safely with the wrapper, deprecation warnings and release notes.
Projects and Practice
- Project: Build a Multi-module Java Application with Gradle A hands-on Gradle project: build a three-module Java application with a convention plugin, version catalog, tests, coverage and a distribution, plus a runnable model of the app logic.
- Project: A Custom Gradle Plugin with a Task, Extension and Tests Build a real Gradle plugin step by step: a changelog task with typed inputs and outputs, an extension, plugin registration, TestKit tests and a runnable Java model of its logic.
- Project: A CI Pipeline for a Gradle Build (GitHub Actions) Set up continuous integration for a Gradle project: GitHub Actions workflow, wrapper validation, caching, test reports, matrix builds, publishing on tags and pipeline planning stand-ins.
- Troubleshooting Gradle Builds: Errors, Commands and Practice Fix common Gradle problems: dependency resolution, version conflicts, out of memory, stale caches, wrapper issues, plus a command cheat sheet and practice exercises with runnable stand-ins.