70
GRADLE 4.0 ETIENNE STUDER, VP OF PRODUCT TOOLING, GRADLE INC.

GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Embed Size (px)

Citation preview

Page 1: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

GRADLE 4.0ETIENNE STUDER, VP OF PRODUCT TOOLING, GRADLE INC.

Page 2: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 2

E"enne Studer

C: Gradle Inc. P: Gradle Enterprise

E: e"[email protected] T: @e"ennestuder G: github.com/e"ennestuder

Page 3: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable
Page 4: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 4

DOWNLOADS/ MONTH4.0M

Page 5: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 5

OSS PROJECTSWORLD-WIDE#17

Page 6: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 6

GRADLE ENGINEERS30

Page 7: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Gradle 1-min intro

Page 8: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 8

Gradle build execu3on

Gradle build scripts Gradle tasks Gradle task execu3on

2-phase build:

Configura3on phase → build task graph (DAG)

Execu3on phase → execute task graph

Page 9: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 9

Demo

Gradle 1-min intro

Page 10: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Incremental builds

Page 11: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Typically, not much changes in the build between

consecu3ve invoca3ons of the build.

When liQle changes in the build, liQle work should be done

by the build.

Reuse outcomes of the previous run.

Observa3on

Page 12: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Task inputs and outputs

Only run a task if its input or outputs have changed since the

previous run.

Inputs —> Task —> Outputs

Example for Compile task:

Task inputs: source files, compiler flags, etc.

Task output: class files

Page 13: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 13

Demo

Incremental builds

Page 14: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Build cache

Page 15: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 15

Build cache

• Reuse outcomes of any previous run (rather than just the last) • Local cache and remote cache • Task output caching

Page 16: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Calculate cache key from inputs, use output as cache value

Inputs —> Task —> Output

Example for Compile task:

Cache key: hash(source files, compiler flags, etc.)

Cache value: fileTree(class files)

Build cache

Page 17: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 17

Demo

Build cache

Page 18: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 18

Build cache

Remote Cache

Local Cache

CI

Developer

Page 19: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 19

Build cache

buildCache {

local {

enabled = !isCI

}

remote(HttpBuildCache) {

url = ‘https://my.ge.server/cache/'

push = isCI

}

}

Page 20: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 20

Build cache

Page 21: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 21

Build cache

Android • Gradle tasks of Android plugin will become cacheable • Caching transformed dependencies possibly in the future

Page 22: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 22

• hQps://blog.gradle.org/introducing-gradle-build-cache • hQps://docs.gradle.org/3.5/userguide/build_cache.html • High-performant, scalable build cache implementa3on

available in Gradle Enterprise • hQps://gradle.com/build-cache

Build cache

Page 23: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Compile avoidance & incremental compiler

Page 24: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 24

Avoid was3ng 3me compiling source classes that do not have to be compiled.

Compile avoidance & incremental compiler

Page 25: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 25

Compile avoidance & incremental compiler

app

library

Page 26: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 26

Demo

Compile avoidance & incremental compiler

Page 27: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 27

Compile avoidance & incremental compiler

Page 28: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 28

Compile avoidance & incremental compiler

Page 29: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 29

• hQps://blog.gradle.org/incremental-compiler-avoidance • hQps://docs.gradle.org/current/userguide/java_plugin.html

Compile avoidance & incremental compiler

Page 30: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

General performance improvements

Page 31: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 31

• Faster configura3on 3me • Parallel dependency resolu3on • Parallel task / ac3on execu3on by default

General performance improvements

Page 32: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Gradle daemon

Page 33: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 33

Gradle builds executed much more quickly by a long-lived

background process that avoids expensive bootstrapping and

leverages caching.

Gradle daemon

Page 34: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 34

Demo

Gradle daemon

Page 35: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 35

• hQps://docs.gradle.org/current/userguide/gradle_daemon.html

Gradle daemon

Page 36: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Worker API

Page 37: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 37

Worker API

• API to run task ac3ons in parallel safely • Parallel ac3ons cannot mutate shared state • Supports out-of-process and in-process ac3ons

Page 38: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Con"nuous build

Page 39: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 39

Demo

Con3nuous build

Page 40: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 40

• hQps://blog.gradle.org/introducing-con3nuous-build • hQps://docs.gradle.org/current/userguide/con3nuous_build.html

Con3nuous build

Page 41: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Composite builds

Page 42: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 42

Composite builds

• Fix a bug in a library through app using project • Break down a monolith into mul3ple repos • Consume latests state of libraries in integra3ons builds

Page 43: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 43

Demo

Composite builds

Page 44: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 44

• hQps://blog.gradle.org/introducing-composite-builds • hQps://blog.jetbrains.com/idea/2017/03/webinar-recording-

composite-builds-with-gradle • hQps://docs.gradle.org/current/userguide/

composite_builds.html

Composite builds

Page 45: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

New Gradle console

Page 46: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

IDE integra"on

Page 47: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 47

IDE integra3on

• Project import & synchroniza3on • Task execu3on • Test execu3on • Build execu3on insights

Build is the single source of truth!

Page 48: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 48

Tooling API

LauncherTooling API

Server

Cmd Line(build master)

(cont integra3on)

Gradle (daemon)

IDE(developer)

Page 49: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 49

Demo

IDE integra3on

Page 50: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 50

• hQps://blog.gradle.org/announcing-buildship-2.0 • hQps://marketplace.eclipse.org/content/buildship-gradle-

integra3on

IDE integra3on

Page 51: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Gradle Script Kotlin

Page 52: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 52

Gradle Script Kotlin

• Syntax highligh3ng • Quick documenta3on • Naviga3on to source • Auto-comple3on / content assist • Refactoring

• High execu3on 3me performance

Build code is no different to applica5on code!

Page 53: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 53

• hQps://blog.gradle.org/kotlin-meets-gradle • hQps://github.com/gradle/gradle-script-kotlin

Gradle Script Kotlin

Page 54: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Gradle Profiler

Page 55: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 55

• Profiling and benchmarking • DSL to describe scenarios (tasks, Gradle version, etc.) • Profiles for Build scans, YourKit, Chrome Trace, etc. • Build life-cycle insights derived from build opera3ons

Gradle Profiler

Page 56: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 56

• github.com/gradle/gradle-profiler

Gradle Profiler

Page 57: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Build scans

Page 58: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 58

Build scans

• Gain build insights • Improve build performance • Collaborate with colleagues and the community

Page 59: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 59

Build scans

Demo

Page 60: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 60

Build scans

Page 61: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 61

• hQps://gradle.com • hQps://gradle.com/scans/get-started

Build scans

Build scans are a free service for everyone!

Page 62: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Gradle Enterprise

Page 63: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 63

Gradle Enterprise

• Query scans • Compare scans • Use a high-performance, scalable build cache • Host within your firewall

Gain deep build insights within your company and teams!

Page 64: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 64

Gradle Enterprise

Demo

Page 65: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 65

• hQps://gradle.com/enterprise

Gradle Enterprise

Gradle Enterprise is a commercial offering!

Page 66: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Android

Page 67: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 67

Android plugin 2.5

• Close collabora3on between Gradle and Google Android Team

Page 68: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 68

Android plugin 2.5

• No more dependency resolu3on at configura3on 3me • Parallel dependency resolu3on (ar3facts / metadata download) • Dependencies always only downloaded once per build • Variant-aware dependency management • More fine-grained parallelism • Compile avoidance • Explicit annota3on-processor declara3on • Linear growth when new variants are added • Android tasks will be cacheable

Page 69: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

| 69

• Incremental builds • Build cache • Compile avoidance & incremental compiler • Worker API • Daemon • Con3nuous builds • Composite builds • Tooling API • Sta3cally-typed DSL • Build scans • Gradle Enterprise

Gradle

Used by

Page 70: GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable

Thank youE3enne Studer