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 full-size 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 full-size slide

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

    View full-size 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 full-size slide

  5. Fast builds
    3 . 1

    View full-size slide

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

    View full-size slide

  7. Incremental builds
    Gradle
    Maven
    3 . 3

    View full-size slide

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

    View full-size slide

  9. We can do be er!
    3 . 5

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  13. 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 full-size slide

  14. 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 full-size slide

  15. Build Cache – Demo
    3 . 12

    View full-size slide

  16. 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 full-size slide

  17. Local and remote cache
    3 . 14

    View full-size slide

  18. Reliable builds
    4 . 1

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  21. 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 full-size slide

  22. 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 full-size slide

  23. Build Scans – Demo
    4 . 6

    View full-size slide

  24. 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 full-size slide

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

    View full-size slide

  26. 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 full-size slide

  27. Дякую!
    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 full-size slide