O'Reilly logo
live online training icon Live Online training

Gradle: The basics and beyond

Ken Kousen

Gradle is the build tool of choice in the open source world, and it’s rapidly becoming the standard in industry as well. Join expert Ken Kousen for a detailed exploration of fundamental Gradle concepts, such as projects, tasks, and the Gradle domain-specific language (DSL), as well as more advanced Gradle features, such as file manipulation, incremental builds, generating the Gradle wrapper, and resolving conflicts in dependencies. Along the way, you’ll learn how to write your own custom task classes and create Gradle plugins from them, use Gradle’s build-scan capability to analyze build files, and profile your build and determine dependencies. You'll leave with a firm foundation in Gradle basics and hands-on experience tackling more advanced concepts and components.

What you'll learn-and how you can apply it

By the end of this live online course, you’ll understand:

  • The basics of Gradle projects and tasks
  • The Gradle domain-specific language (DSL)
  • How to use Gradle’s build-scan capability to analyze your build
  • How to perform file manipulation
  • How to implement incremental builds and task avoidance

And you’ll be able to:

  • Write your own ad hoc tasks and custom task classes
  • Profile your build and measure performance
  • Generate the Gradle wrapper with different versions and capabilities
  • Resolve conflicts in dependencies

This training course is for you because...

  • You're an experienced Java developer who wants to understand the latest Gradle features.
  • You're a team member or leader who needs to build and support Gradle applications.
  • You want to learn more about custom task classes, plugins, and incremental build features in Gradle.

Prerequisites

  • Familiarity with build systems like Ant or Maven (useful but not required)
  • A basic understanding of Java (useful but not required)

Required materials and setup:

A machine with any recent version of Gradle installed, as well as Java 7 or 8.

Recommended preparation:

Groovy (Learning Path)

Recommended follow-up:

Getting Started with Gradle (Learning Path)

Gradle Custom Tasks, Plugins, and Miscellaneous Features (Learning Path)

Basic Project Builds in Gradle (Learning Path)

About your instructor

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Day 1

Gradle overview and installation (20 minutes)

  • Lecture: Where to get the distribution; the Gradle open source project; using SDK Manager; the zip install
  • Hands-on exercise: Confirm the Gradle install and run the daemon

Basic Groovy (40 minutes)

  • Lecture: Data types and classes; strings and other basic classes; collections; closures and delegates; examples
  • Hands-on exercise: Use strings, collections, and closures

Break (10 minutes)

Gradle build files (40 minutes)

  • Lecture: Project and tasks; shortcuts; the build lifecycle; common tasks; the Gradle daemon; the Gradle wrapper; extension properties
  • Hands-on exercise: Explore the Gradle build lifecycle

Tasks (35 minutes)

  • Lecture: DSL syntax; ad hoc versus typed tasks; implementing task types
  • Hands-on exercise: Create tasks

Break (10 minutes)

Filesystem tasks (35 minutes)

  • Lecture: Files and directory tasks; copy and sync; archive tasks; unarchiving and merging
  • Hands-on exercise: Use copying, archiving, and expanding

The Java plugin (40 minutes)

  • Lecture: Java tasks; the directed acyclic graph; source sets; basic dependencies and repositories
  • Hands-on exercise: Build a Java project

Wrap-up and Q&A (10 minutes)

Day 2

Dependency management (40 minutes)

  • Lecture: Unmanaged dependencies; configurations; transitive dependencies; conflict resolution; dynamic dependencies; build scans
  • Hands-on exercise: Add dependencies and resolve conflicts

Break (10 minutes)

Incremental builds (30 minutes)

  • Lecture: Setting inputs and outputs; inputs and outputs in build tasks; using onlyIf; programmatic exclusions
  • Hands-on exercise: Selective execution

Ordering tasks (30 minutes)

  • Lecture: Using dependsOn; the mustRunAfter and shouldRunAfter tasks; finishing with finalizedBy
  • Hands-on exercise: Set task order

Break (10 minutes)

Multiproject builds (30 minutes)

  • Lecture: Using settings.gradle; collecting common dependencies and tasks; executing tasks in subprojects; parallel execution
  • Hands-on exercise: Configure a multiproject build

Selected plugins (30 minutes)

  • Lecture: Build init; Java, Groovy, and other JVM plugins; web applications with Gretty; the Gradle Plugin Portal; IDE support
  • Hands-on exercise: Use Gradle plugins

Break (10 minutes)

Creating plugins (40 minutes)

  • Lecture: Script plugins; binary plugins; using the buildSrc directory; declaring plugin IDs; packaging and deployment
  • Hands-on exercise: Write a plugin

Further work, wrap-up, and Q&A (10 minutes)