Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fast and reliable builds with Gradle and Maven

Fast and reliable builds with Gradle and Maven

Having fast and reliable builds has a major influence on developer productivity. Faster builds make feedback cycles shorter by reducing wait times and context switches for developers. If a build is unreliable, developers may re-run the same build over and over again and when that fails, run a clean build and/or clear all the caches. Doing so removes many of the performance optimizations of the build tool, forcing every step of the build to be recomputed which takes much longer than an incremental build.

In this session, we will show you how Gradle Enterprise can be used for both Gradle and Maven to make builds faster and more reliable through build caching and build scans, respectively. The build cache, very different from the m2 cache, stores the outputs of each step of the build on a remote server. These cached outputs can then be used by both developer and CI builds. We’ll also dive into ways to increase the speed and reliability of each step of the build using build scans. Build scans provide insights into where bottlenecks occur and provide the data to optimize problems specific to your build.

Marc Philipp

April 26, 2019
Tweet

More Decks by Marc Philipp

Other Decks in Programming

Transcript

  1. Fast and reliable builds with
    Gradle and Maven
    Marc Philipp (@marcphilipp), Gradle Inc.
    1

    View Slide

  2. About me
    speaker {
    name = "Marc Philipp"
    home = "Karlsruhe, Germany"
    company = "Gradle Inc."
    title = "Senior Software Engineer"
    openSourceRoles = [
    "JUnit team lead"
    ]
    twitter = "@marcphilipp"
    github = "marcphilipp"
    web = uri("https://www.marcphilipp.de")
    }
    2 . 1

    View Slide

  3. Gradle Inc.
    Build Happiness
    Products
    Gradle Build Tool
    Gradle Enterprise
    2 . 2

    View Slide

  4. How do builds affect
    developer produc vity?
    failures: about 20% of builds fail due to code defects
    5‑10% of a team’s capacity is spent on fixing
    slowness: a team’s capacity is reduced by 4% for
    each extra minute of build me
    unreliability: 5% of a team’s capacity goes into
    debugging build problems
    2 . 3

    View Slide

  5. Fast builds
    3 . 1

    View Slide

  6. Fast builds
    faster = avoid doing needless work
    reuse results!
    incremental builds
    build cache
    3 . 2

    View Slide

  7. Incremental builds
    Gradle
    Maven
    3 . 3

    View Slide

  8. Incremental builds
    Gradle can reuse results
    of the last me
    this build ran
    on this machine.
    3 . 4

    View Slide

  9. We can do be er!
    3 . 5

    View Slide

  10. Why not…
    of any me
    and any build
    that ran anywhere.
    3 . 6

    View Slide

  11. Even be er
    For Maven and Gradle builds!
    3 . 7

    View Slide

  12. 3 . 8

    View Slide

  13. Build Cache for Gradle
    $> gradle ­­build­cache assemble
    :compileJava FROM­CACHE
    :processResources
    :classes
    :jar
    :assemble
    BUILD SUCCESSFUL
    3 . 9

    View Slide

  14. Build Cache for Gradle
    out‑of‑the‑box for Java, Groovy, Scala, C++ and
    Swi projects
    supports compile, test and verifica on tasks
    high‑performance remote backend from Gradle
    Docker Hub: gradle/build‑cache‑node
    3 . 10

    View Slide

  15. Build Cache for Maven
    custom extension (part of Gradle Enterprise)
    ini al release: March 2019
    supported plugins: Java Compiler, Surefire/Failsafe,
    Javadoc, JAXB, Checkstyle
    3 . 11

    View Slide

  16. Build Cache – Demo
    3 . 12

    View Slide

  17. How does it work?
    Calculate cacheKey of a task/goal from its inputs:
    cacheKey(javaCompile) = hash(sourceFiles, … )
    Store its outputs under cacheEntry:
    cacheEntry(javaCompile) = fileTree(classFiles)
    Gradle task
    Inputs Outputs
    3 . 13

    View Slide

  18. Local and remote cache
    3 . 14

    View Slide

  19. 3 . 15

    View Slide

  20. 3 . 16

    View Slide

  21. 3 . 17

    View Slide

  22. 3 . 18

    View Slide

  23. 3 . 19

    View Slide

  24. 3 . 20

    View Slide

  25. 3 . 21

    View Slide

  26. 3 . 22

    View Slide

  27. 3 . 23

    View Slide

  28. 3 . 24

    View Slide

  29. Reliable builds
    4 . 1

    View Slide

  30. Requirements
    monitoring of builds to discover
    regressions/improvements
    both builds by developers and CI
    reliability
    performance
    4 . 2

    View Slide

  31. What are Build Scans?
    persistent record of what happened during a build
    permanent and shareable URL
    for developers and build engineers
    4 . 3

    View Slide

  32. Gradle
    $> gradle build ­­scan
    ...
    BUILD SUCCESSFUL in 8m 22s
    418 actionable tasks: 112 executed, 48 from cache, 258 up­
    Publishing build scan...
    https://scans.gradle.com/s/lbmn7n4dngqgq
    4 . 4

    View Slide

  33. Maven
    (with extension registered in .mvn/extensions.xml)
    $> mvn clean verify
    ...
    [INFO] ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
    [INFO] BUILD SUCCESS
    [INFO] ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
    [INFO] Total time: 5.262 s
    [INFO] Finished at: 2019­04­23T09:55:36+02:00
    [INFO] ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
    [INFO] 13 goals, 8 executed, 5 from cache, saving at least
    [INFO]
    [INFO] Publishing build scan...
    [INFO] https://gradle.com/s/ypgljbvelzxzs
    [INFO]
    4 . 5

    View Slide

  34. Build Scans – Demo
    4 . 6

    View Slide

  35. Build Scans
    support Gradle and Maven
    public scans are free on
    without build comparison, performance
    dashboard etc.
    Gradle Enterprise provides addi onal features and
    on‑premise hos ng
    scans.gradle.com
    h ps:/
    /scans.gradle.com/s/nq7w6cjm72mak/
    4 . 7

    View Slide

  36. Custom analyses
    use Export API
    h ps:/
    /github.com/gradle/build‑analysis‑demo
    4 . 8

    View Slide

  37. 4 . 9

    View Slide

  38. 4 . 10

    View Slide

  39. Resources
    Free trainings on , e.g.
    Build Cache Deep Dive
    Maven + Gradle Enterprise
    Gradle Build Tool:
    Gradle Enterprise:
    h ps:/
    /gradle.com/training/
    YouTube channel
    h ps:/
    /gradle.org
    h ps:/
    /gradle.com
    5 . 1

    View Slide

  40. Дякую!
    See you tomorrow?
    5
    From Revolu on to Con nuous Evolu on
    Tomorrow, 16:10, Track C
    News from JUnit 5.x
    5 . 2

    View Slide