What's new in Gradle 4.0
Eric Wendelin — JavaOne 2017
Eric Wendelin
@eriwen
3-minute Gradle Overview
From mobile apps to microservices, from small
startups to big enterprises, Gradle helps teams
build, automate and deliver beGer soHware, faster.
Automate Everything
Integrates with other tools like
Docker for development or
opera7ons.
Integrates with and delegates to
NPM, MSBuild, Ant, and other
tools.
Build Anything
Support for Java, C/C++, Python,
JavaScript, Go, and other
languages.
Go monorepo, mul7-repo, or
anywhere in-between.
Trusted by Millions
Official build tool for Android
4M+ downloads per month
#17 on BaOery OSS Index
Gradle Overview
Languages built by Gradle
4%
7%
13%
21%
55%
GITHUB PUBLIC
SOURCE BYTES
Java
C
JS/CSS/HTML
C++
Groovy/Kotlin/Other
#BigQuery hOps://git.io/vQfUx
Gradle Build Anatomy
3-phase build:
IniKalizaKon → evaluate seNngs
ConfiguraKon → build task graph
ExecuKon → execute task graph
Evaluate Gradle scripts Execute tasksBuild DAG
Incremental Builds
TaskInputs Outputs
UP-TO-DATE
EXECUTE
same contents ? same contents ?
Gradle 3.0 => Sep 19, 2016
Gradle 4.0 => Jun 14, 2017
Gradle 4.2.1 => Current Version
Brief Gradle Version History
‣ Incremental Compile
‣ Compile Avoidance
‣ Build Cache
‣ Parallelism
Shipped since Gradle 3.0
Performance
✦ Buildship 2.0
✦ Kotlin DSL
✦ Improved CLI
✦ Build Scans
User Experience
❖ Java Library Plugin
❖ Java 9 Support
❖ NaKve Build Features
❖ Composite Builds
New Tools
Shipped since Gradle 3.0
‣ Incremental Compile
‣ Compile Avoidance
‣ Build Cache
‣ Parallelism
Performance
✦ Buildship 2.0
✦ Kotlin DSL
✦ Improved CLI
✦ Build Scans
User Experience
❖ Java Library Plugin
❖ Java 9 Support
❖ NaKve Build Features
❖ Composite Builds
New Tools
Incremental CompilaKon
Performance
• Analyze class dependencies to opKmize

which classes are recompiled
• Fast in-memory cache of class ABIs inside
daemon
Incremental Compila7on for Java
Lorem ipsum Lorem ipsum Lorem ipsum
Incremental Compila7on
Incremental Compila7on
tasks.withType(JavaCompile) {
options.incremental = true
}
Recommended JavaOne Talk: Maximizing
Incrementality with Gradle
- Cedric Champeau at 12:15pm tomorrow [CON2992]
Incremental Compila7on
Compile Avoidance
Performance
Gradle recognizes ABI breaking changes,
and will trigger recompilaKon only when ABI
is changed.
Compile Avoidance
Compile Avoidance Example
Does MyApp need
to be recompiled?
No!
edub.me/compile-avoidance
Build Cache
Performance
buildCache {
local {
enabled = !isCI
}
remote(HttpBuildCache) {
url = "https://my.ge.server/cache/"
push = isCI
}
}
CI
Remote
Cache
Local
Cache
Developer
Build Cache
As of Gradle 4.2, Java and Scala toolchains are
cacheable by default. We're working on leveraging
this for all sensible tasks.
Self-hosted Build Scans
Collect build history across all
Gradle builds.
Export build data; perform trend
analysis and data-driven
engineering effec7veness.
gradle.com/build-scans
Enterprise Build Cache
Easy installa7on and maintenance
tools for the Gradle Build Cache.
Enjoy much faster builds by
reusing task outputs across
machines.
gradle.com/build-cache
Support and ConsulQng
Get help migra7ng or upgrading
Gradle.
Expert build op7miza7on, saving
7me and improving developer
happiness.
gradle.org/services
Gradle Enterprise
Enterprise-grade Build Cache & Build Scans
gradle.com/build-cache
Parallelism
Performance
Parallel Dependency Downloads
Worker API
Without Worker API Using Worker API
edub.me/worker-api
Other Performance Improvements
Performance
• Faster configuraKon
• Faster gradle tasks
• Faster archive processing
• Faster daemon communicaKon
• lots more...
Performance Improvements
Gradle 4.2 is 2-100x faster than Gradle 3.0 when using
all of the new performance features — upgrade!
Summary
Shipped since Gradle 3.0
‣ Incremental Compile
‣ Compile Avoidance
‣ Build Cache
‣ Parallelism
Performance
✦ Buildship 2.0
✦ Kotlin DSL
✦ Improved CLI
✦ Build Scans
User Experience
❖ Java Library Plugin
❖ Java 9 Support
❖ NaKve Build Features
❖ Composite Builds
New Tools
Java Library Plugin
New Tools
compile: dependencies needed to compile

runtime: dependencies needed to run project
Java Library Plugin
Not sufficient!
There are at least 2 kinds of Java projects:
applicaQons (standalone, no API) 

libraries (exposes an API)
Java Library Plugin
// For Java Libraries that expose an API
- apply plugin: "java"
+ apply plugin: "java-library"
dependencies {
- compile "org.apache.commons:commons-math3:3.6.1"
- compile "com.google.guava:21.0"
+ api "org.apache.commons:commons-math3:3.6.1"
+ implementation "com.google.guava:21.0"
}
edub.me/java-library-plugin
Java 9 Support
New Tools
Gradle 4.2.1 provides runKme support for Java 9
applicaKons and libraries.
It does not have first-class support for Java 9
modules yet.
Java 9 Support
1. Add module-info.java
2. Modify JavaCompile tasks to produce
modules
3. Modify compile test tasks to patch modules
4. Modify Test tasks to consume patched
modules
Adop7ng Java 9 modules using Gradle
Using Java 9 modules with Gradle
ext.moduleName = "org.gradle.actors"
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = ["--module-path", classpath.asPath]
classpath = project.files()
}
}
Java 9 Support
plugins {
id "org.gradle.java.experimental-jigsaw" version "0.1.1"
}
DO NOT USE THIS PLUGIN IN PRODUCTION!
edub.me/gradle-java9
NaKve Build Features
New Tools
• Parallel compilaKon and linking by default
• VS2015 Support
• Build Dependents
Na7ve Build Features
Composite Builds
New Tools
gradle myTask --include-build ../separate-project
| X
Composite Builds
• Combine independent Gradle builds
• SubsKtute binary with project dependencies
• Quick local experimentaKon
• Cross-repository refactoring
• Smooth migraKon from monolith to mulK-repo
• Faster plugin prototyping
edub.me/composite-builds
Shipped since Gradle 3.0
‣ Incremental Compile
‣ Compile Avoidance
‣ Build Cache
‣ Parallelism
Performance
✦ Buildship 2.0
✦ Kotlin DSL
✦ Improved CLI
✦ Build Scans
User Experience
❖ Java Library Plugin
❖ Java 9 Support
❖ NaKve Build Features
❖ Composite Builds
New Tools
Buildship 2.0
User Experience
• Composite Build support
• Fresh new design
• --offline mode support
Buildship 2.0
Kotlin DSL
User Experience
• Auto-compleKon and content assist
• Quick documentaKon
• NavigaKon to source
• Refactoring and more
Kotlin DSL
edub.me/kotlin-dsl-samples
Improved CLI
User Experience
git.io/gradle-compleKon
• CompleKon for tasks, flags, and common
properKes
• Available for bash and zsh
• Kotlin build scripts support
• ~20x faster than alternaKves for medium
to large projects
Build Scans
User Experience
• Persistent
• Shareable
• Customizable
• Fast
Build Scans
• Trend analysis
• A/B tesKng (Build Comparison)
• Flaky test detecKon
• Engineering workflow opKmizaKon
Pufng Build Scans Together
gradle.com/build-scans
gradle myTask --scan
‣ Incremental Compile
‣ Compile Avoidance
‣ Build Cache
‣ Parallelism
Shipped since Gradle 3.0
Performance
✦ Buildship 2.0
✦ Kotlin DSL
✦ Improved CLI
✦ Build Scans
User Experience
❖ Java Library Plugin
❖ Java 9 Support
❖ NaKve Build Features
❖ Composite Builds
New Tools
• gradle.org/guides — Get started using
various technologies with Gradle
• gradle.org/training — Monthly free online
training with core engineers
• gradle.com/enterprise — Build together;
not alone
Learn More
@eriwen
@gradle
w
Thank You
Eric Wendelin — @eriwen

What's new in Gradle 4.0