Slide 1

Slide 1 text

Becoming and Staying a Productive Developer with Build Scans, Build Validation Scripts, and Gradle Nelson Osacky, Lead Solutions Engineer Etienne Studer, SVP of Engineering

Slide 2

Slide 2 text

Etienne • SVP of Engineering, Develocity • Leading the Develocity Engineering team • Creator and former lead of the Gradle Solu ti ons team

Slide 3

Slide 3 text

Nelson • Lead Solu ti ons Engineer, Develocity • Leading the Gradle Solu ti ons team • Previously Android Engineer (SoundCloud, Square) • Gradle Plugin Maintainer • Fladle — Easily Scale Instrumenta ti on Tests on Firebase • Gradle Doctor — Ac ti onable Insights for your build

Slide 4

Slide 4 text

Develocity formerly known as Gradle Enterprise

Slide 5

Slide 5 text

• Helping teams of 50-10k engineers • Upgrading and optimizing builds • Migrating builds • Scaling builds Gradle Solutions team

Slide 6

Slide 6 text

• Improving the Gradle ecosystem • Fixing issues in OSS plugins • Aligning with Google and JetBrains • … Gradle Solutions team

Slide 7

Slide 7 text

High Friction in Developer Productivity

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Developer Productivity Engineering (DPE)

Slide 10

Slide 10 text

DPE is a new software development practice used by leading software development organizations to maximize developer productivity and happiness.

Slide 11

Slide 11 text

• Capture toolchain data • Accelerate and stabilize toolchain • Measure impact of improvements

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Costs of Inefficiency 60s waste * 50 builds / day * 50 devs 
 = 42 hours lost / day h tt ps:/ /gradle.com/roi-calculator

Slide 17

Slide 17 text

• Build insights for artifact transforms • Build caching optimizations • Develocity API usage Examples

Slide 18

Slide 18 text

Artifact transforms

Slide 19

Slide 19 text

What are artifact transforms? • Dependency management concept • Changes dependency from incorrect format to requested format via Ar ti fact Transforms • Example: classes jar to dex fi le • Users do not directly request transforms • Gradle schedules Transforms between units of work • Transforms can depend on tasks or transforms

Slide 20

Slide 20 text

Artifact transforms are now visible in Build Scan! 🥳 Requires Develocity 2023.1+, Develocity Gradle Plugin 3.13+, Gradle Build Tool 8.1+ 
 Only visualizes project ar ti fact transforma ti ons in Develocity 2023.3

Slide 21

Slide 21 text

Artifact transforms are now visible in Build Scans!

Slide 22

Slide 22 text

Artifact transforms are now visible in Build Scans! Details and dura ti on

Slide 23

Slide 23 text

Why are transforms important in Build Scans? • Understand transform dependencies • Understand gaps in ti meline • Understand ar ti fact transform up-to-date, caching, etc • View transform logs

Slide 24

Slide 24 text

Understand transform dependencies

Slide 25

Slide 25 text

Transform visibility fills gaps in timeline

Slide 26

Slide 26 text

Transform visibility fills gaps in timeline

Slide 27

Slide 27 text

Artifact transforms upcoming work • Ar ti fact Transform Execu ti ons insights • Upcoming in Develocity 2023.4, Gradle Build Tool 8.4

Slide 28

Slide 28 text

Build Caching https:/ /docs.gradle.org/current/userguide/build_cache.html

Slide 29

Slide 29 text

JavaCompile task Source Files Compiler Args Dependencies Class files any task can be made cacheable

Slide 30

Slide 30 text

Cache key Source Files Compiler Args Dependencies

Slide 31

Slide 31 text

Cache key Source Files Compiler Args Dependencies Build cache Class files

Slide 32

Slide 32 text

What is a cache miss?

Slide 33

Slide 33 text

What is a cache miss? •Expect a cache hit but cache key is di ff erent •Task outcome is the same •Only inputs that a ff ect outcome should be tracked

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Task inputs comparison

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Common Cache misses

Slide 38

Slide 38 text

Build Configuration Differences

Slide 39

Slide 39 text

Build Configuration Differences

Slide 40

Slide 40 text

Build Configuration Differences kotlin.incremental=false kotlin.incremental=true CI Local

Slide 41

Slide 41 text

Build Configuration Differences kotlin.incremental=false kotlin.incremental=true CI Local Incremental has no effect on outcome of task

Slide 42

Slide 42 text

Build Configuration Differences kotlin.incremental=true kotlin.incremental=true CI Local Incremental has no effect on outcome of task h tt ps:/ /youtrack.jetbrains.com/issue/KT-40974/isIncrementalCompila ti onEnabled-should-not-be-marked-as-Input

Slide 43

Slide 43 text

LiveLiterals

Slide 44

Slide 44 text

LiveLiterals

Slide 45

Slide 45 text

LiveLiterals

Slide 46

Slide 46 text

•LiveLiterals$AnalyticsEvent.kt contains fully qualified path •Fix is to disable LiveLiterals composeOptions { useLiveLiterals = false } LiveLiterals https://issuetracker.google.com/issues/233716574

Slide 47

Slide 47 text

KSP Cache misses

Slide 48

Slide 48 text

KSP Cache misses

Slide 49

Slide 49 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs

Slide 50

Slide 50 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { }

Slide 51

Slide 51 text

Debugging task inputs tasks.withType().configureEach { } KspTaskJvm.pluginOptions.$0.asTaskInputArgs

Slide 52

Slide 52 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { } }

Slide 53

Slide 53 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { } }

Slide 54

Slide 54 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { } }

Slide 55

Slide 55 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { pluginOptions.get().forEach { } } }

Slide 56

Slide 56 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { pluginOptions.get().forEach { } } }

Slide 57

Slide 57 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { pluginOptions.get().forEach { } } }

Slide 58

Slide 58 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { pluginOptions.get().forEach { it.getAsTaskInputArgs().forEach { } } } }

Slide 59

Slide 59 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { pluginOptions.get().forEach { it.getAsTaskInputArgs().forEach { } } } }

Slide 60

Slide 60 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { pluginOptions.get().forEach { it.getAsTaskInputArgs().forEach { buildScan.value( "${[email protected]}-${it.key}", it.value, ) } } } }

Slide 61

Slide 61 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { pluginOptions.get().forEach { it.getAsTaskInputArgs().forEach { rootProject.buildScan.value( "${[email protected]}-${it.key}", it.value, ) } } } }

Slide 62

Slide 62 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs tasks.withType().configureEach { doLast { pluginOptions.get().forEach { it.getAsTaskInputArgs().forEach { rootProject.buildScan.value( "${[email protected]}-${it.key}", it.value, ) } } } }

Slide 63

Slide 63 text

Debugging task inputs KspTaskJvm.pluginOptions.$0.asTaskInputArgs

Slide 64

Slide 64 text

KSP Cache misses build.gradle.kts class RoomSchemaArgProvider( @get:InputDirectory @get:PathSensitive(PathSensitivity.RELATIVE) val schemaDir: File, ) : CommandLineArgumentProvider { override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}") } extensions.configure { arg(RoomSchemaArgProvider(File(projectDir, "schemas"))) } h tt ps:/ /developer.android.com/training/data-storage/room/migra ti ng-db-versions#test

Slide 65

Slide 65 text

KSP Cache misses build.gradle.kts class RoomSchemaArgProvider( @get:InputDirectory @get:PathSensitive(PathSensitivity.RELATIVE) val schemaDir: File, ) : CommandLineArgumentProvider { override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}") } extensions.configure { arg(RoomSchemaArgProvider(File(projectDir, "schemas"))) } h tt ps:/ /developer.android.com/training/data-storage/room/migra ti ng-db-versions#test

Slide 66

Slide 66 text

KSP Cache misses build.gradle.kts class RoomSchemaArgProvider( @get:InputDirectory @get:PathSensitive(PathSensitivity.RELATIVE) val schemaDir: File, ) : CommandLineArgumentProvider { override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}") } extensions.configure { arg(RoomSchemaArgProvider(File(projectDir, "schemas"))) } h tt ps:/ /developer.android.com/training/data-storage/room/migra ti ng-db-versions#test

Slide 67

Slide 67 text

KSP Cache misses build.gradle.kts class RoomSchemaArgProvider( @get:InputDirectory @get:PathSensitive(PathSensitivity.RELATIVE) val schemaDir: File, ) : CommandLineArgumentProvider { override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}") } extensions.configure { arg(RoomSchemaArgProvider(File(projectDir, "schemas"))) } h tt ps:/ /developer.android.com/training/data-storage/room/migra ti ng-db-versions#test

Slide 68

Slide 68 text

KSP Cache misses KspTaskJvm.pluginOptions.$0.asTaskInputArgs

Slide 69

Slide 69 text

KSP Cache misses build.gradle.kts class RoomSchemaArgProvider( @get:InputDirectory @get:PathSensitive(PathSensitivity.RELATIVE) val schemaDir: File, ) : CommandLineArgumentProvider { override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}") }

Slide 70

Slide 70 text

KSP Cache misses build.gradle.kts class RoomSchemaArgProvider( @get:InputDirectory @get:PathSensitive(PathSensitivity.RELATIVE) val schemaDir: File, ) : CommandLineArgumentProvider { override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}") }

Slide 71

Slide 71 text

KSP Cache misses KspSubplugin.kt commandLineArgumentProviders.get().forEach { it.asArguments().forEach { argument -> options += SubpluginOption("apoption", argument) } }

Slide 72

Slide 72 text

KSP Cache misses KspSubplugin.kt commandLineArgumentProviders.get().forEach { it.asArguments().forEach { argument -> options += SubpluginOption("apoption", argument) } }

Slide 73

Slide 73 text

KSP Cache misses KspSubplugin.kt commandLineArgumentProviders.get().forEach { it.asArguments().forEach { argument -> options += InternalSubpluginOption("apoption", argument) } }

Slide 74

Slide 74 text

KSP Cache misses KspSubplugin.kt commandLineArgumentProviders.get().forEach { it.asArguments().forEach { argument -> options += InternalSubpluginOption("apoption", argument) } } Fixed in KSP 1.08

Slide 75

Slide 75 text

The case of java.net.URL and .hashCode()

Slide 76

Slide 76 text

The case of java.net.URL and .hashCode() Calling URL.hashCode() vs. not calling URL.hashCode() changes the serialized value of URL

Slide 77

Slide 77 text

The case of java.net.URL and .hashCode()

Slide 78

Slide 78 text

The case of java.net.URL and .hashCode() URL -> URI @get:Input abstract val url: Property @get:Input abstract val url: Property https://www.apollographql.com/blog/mobile/kotlin/how-apollo-kotlin-leverages-gradle-enterprise-to-rev-up-build-times/#1-java-net-url-serializes-di ff erently-depending-if-hashcode-was-called ge.apollographql.com

Slide 79

Slide 79 text

Room Cache Miss

Slide 80

Slide 80 text

Room Cache Miss https://issuetracker.google.com/issues/132245929

Slide 81

Slide 81 text

Room Cache Miss Fixed

Slide 82

Slide 82 text

Room Gradle Plugin plugins { id("androidx.room") version "2.6.0" } room { schemaDirectory("$projectDir/schemas/") } Use Android Cache Fix Plugin 3.0 and Room Gradle Plugin 2.6.0 Thanks Google!

Slide 83

Slide 83 text

Build Caching Verification

Slide 84

Slide 84 text

How Build Caching works Build Caching avoids doing the same work already done before by reusing the work unit output stored in a local or remote build cache.

Slide 85

Slide 85 text

Volatile inputs of work units cause unnecessary execution of work units. Volatility in the inputs of work units

Slide 86

Slide 86 text

Verification if a build is fully cacheable When a build is executed twice under the same conditions, all of the second build’s cache-compatible work units should take their output from the build cache.

Slide 87

Slide 87 text

Automation of the verification process Use the Build Validation Scripts to make the process 
 reliable, repeatable, automated, and productive. https:/ /github.com/gradle/gradle-enterprise-build-validation-scripts

Slide 88

Slide 88 text

Investigation of build cache misses Use Develocity Build Scan Comparison to investigate 
 changes in task inputs that caused a build cache miss. https:/ /ge.solutions-team.gradle.com/c/gxypocyl2jwgq/efifh6cmix5xe/task-inputs

Slide 89

Slide 89 text

Demo

Slide 90

Slide 90 text

Build caching regressions are costly Build changes that make a build no longer fully cacheable must be detected and notifications issued so the regression can be promptly investigated and fixed.

Slide 91

Slide 91 text

Automation of the regression detection The Build Validation Scripts should be run on a continuous base in CI and cause the CI run to fail if a build is 
 no longer fully cacheable. ./03-validate-local-build-caching-different-locations.sh 
 -r https:/ /github.com/spring-projects/spring-framework —fail-if-not-fully-cacheable

Slide 92

Slide 92 text

Example: Continuously verified OSS projects https:/ /github.com/gradle/gradle-enterprise-oss-projects/action

Slide 93

Slide 93 text

Example: Continuously verified OSS projects https:/ /github.com/gradle/gradle-enterprise-oss-projects/actions

Slide 94

Slide 94 text

Cross-machine regression detection The verification process can be extended by orchestrating the execution of two builds of the same version on different machines and submitting them to the Build Validation Scripts to verify full cacheability. ./04-validate-remote-build-caching-ci-ci.sh 
 -1 https:/ /ge.solutions-team.gradle.com/s/gxypocyl2jwgq 
 -2 https:/ /ge.solutions-team.gradle.com/s/efifh6cmix5xe —fail-if-not-fully-cacheable

Slide 95

Slide 95 text

Toolchain data extraction via API

Slide 96

Slide 96 text

Develocity API h tt ps:/ /docs.gradle.com/enterprise/api-manual •REST based •Build models •OpenAPI standard •Allows the genera ti on of models and clients in many languages or technology

Slide 97

Slide 97 text

/api/builds Develocity API •Build Scan Attributes •Build Cache Performance

Slide 98

Slide 98 text

/api/builds/{id}/gradle-attributes Develocity API •Start/End Time •Verification/Non-verification failure •Custom Values, Tags and Links •Gradle settings/options •Environment information

Slide 99

Slide 99 text

/api/builds/{id}/gradle-build-cache-performance Develocity API •Build time •Serial and parallel execution time •Task duration, outcome, avoidance savings and cached artifact size •Local and remote build cache performance •Task fingerprinting summary

Slide 100

Slide 100 text

What can you do with that?

Slide 101

Slide 101 text

• Rank teammates by build time • Task wall of shame • Find longest non-cacheable tasks across all projects • Custom dashboards and alerts

Slide 102

Slide 102 text

Introducing… Develocity Test API 🥳 BETA

Slide 103

Slide 103 text

Retrieve test suites and test case details, filtering by: - test container (e.g test suite, etc) - test outcome (success, failed, flaky etc) - tags - custom values - much more and a combination of all! Develocity Test API BETA

Slide 104

Slide 104 text

Develocity Test API $ curl -H "Authorization: Bearer " \ https://ge.solutions-team.gradle.com/api/tests/containers \ 
 ?container=* \ 
 &testOutcomes=flaky \ 
 &startTimeMax=2023-09-30T10:00:00Z \ 
 &startTimeMin=2023-08-30T10:00:00Z \ BETA

Slide 105

Slide 105 text

Develocity Test API { "content": [ { "name": "com.example.Test", "workUnits": [], "outcomeDistribution": { "passed": 1, "failed": 2, "skipped": 3, "flaky": 4, "notSelected": 5, "total": 15 }, "buildScanIdsByOutcome": {} }, { "name": "com.example.MavenTest", "workUnits": [], "outcomeDistribution": {}, "buildScanIdsByOutcome": {} } ] } $ curl -H "Authorization: Bearer " \ https://ge.solutions-team.gradle.com/api/tests/containers \ ?container=* \ &testOutcomes=flaky \ &startTimeMax=2023-09-30T10:00:00Z \ &startTimeMin=2023-08-30T10:00:00Z \ BETA

Slide 106

Slide 106 text

Develocity Test API $ curl -H "Authorization: Bearer " \ https://ge.solutions-team.gradle.com/api/tests/cases \ ?container=com.example.Test \ &testOutcomes=flaky \ &startTimeMin=2023-08-30T10:00:00Z \ &startTimeMax=2023-09-30T10:00:00Z BETA

Slide 107

Slide 107 text

Develocity Test API { "content": [ { "name": "com.example.Test", "workUnits": [], "outcomeDistribution": { "passed": 1, "failed": 2, "skipped": 3, "flaky": 4, "notSelected": 5, "total": 15 }, "buildScanIdsByOutcome": {} }, ] } $ curl -H "Authorization: Bearer " \ https://ge.solutions-team.gradle.com/api/tests/cases \ ?container=com.example.Test \ &testOutcomes=flaky \ &startTimeMin=2023-08-30T10:00:00Z \ &startTimeMax=2023-09-30T10:00:00Z BETA

Slide 108

Slide 108 text

Develocity Test API What is a fl aky test according to Develocity? • Non-determinis ti c outcome • Fails and succeeds within the execu ti on of a single Gradle task W BETA

Slide 109

Slide 109 text

Prevent flaky tests from creeping in

Slide 110

Slide 110 text

Alert on tests that became flaky

Slide 111

Slide 111 text

Cross reference with your repository structure…

Slide 112

Slide 112 text

… and provide a comprehensive report

Slide 113

Slide 113 text

… and provide a comprehensive report Build Scan® aggrega ti on

Slide 114

Slide 114 text

… and provide a comprehensive report Knowledge on module structure

Slide 115

Slide 115 text

… and provide a comprehensive report Rela ti onship to common code snippets

Slide 116

Slide 116 text

… and provide a comprehensive report Direct ownership assignment based on build scan a tt rs

Slide 117

Slide 117 text

… identify issues earlier

Slide 118

Slide 118 text

… and make it smarter

Slide 119

Slide 119 text

Reach out to us after the talk for access to Develocity Test API BETA Importing Instrumentation Test Results to Develocity BETA

Slide 120

Slide 120 text

More Resources Gradle Training https:/ /gradle.com/training Gradle Community Slack https:/ /gradle.com/slack-invite https://gradle.com/enterprise-customers/oss-projects/ ge.apollographql.com Develocity OSS Projects ge.androidx.dev

Slide 121

Slide 121 text

Thank you! Develocity Trial h tt ps:/ /gradle.com/enterprise/trial/ https:/ /gradle.com/enterprise/trial/ Gradle is hiring Visit our booth downstairs!