Skip to content

gradle/dpeuni-maven-maintaining-optimal-build-cache-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DPE University Training

Checkout all the free Maven, Gradle, and DPE courses at the DPE University!

Maintaining an Optimized Maven Build Cache - Lab

This is a hands-on exercise to go along with the Maintaining Optimal Maven Build Cache Performance training module. In this exercise you will go over how to monitor for build cache misses using build-validation-scripts. These scripts will run two builds and then check for cache misses between them. These scripts can be run locally and via CI. We recommend configuring your CI system to run them at least weekly. This repository demonstrates how to do this with GitHub Actions, but the instructions would be similar for any other CI system.

Prerequisites

Steps

  1. Clone this repository and change to its directory.

  2. If you have not completed other DPE University Maven labs, authenticate Maven with the Develocity server.

Note

As part of taking this free course, you have access to a training instance of Develocity located at:

 https://dpeuniversity-develocity.gradle.com/

Sign in to this Develocity server using the same account you use for the DPE University.

This server is configured so users can only access the Build Scan® and Build Cache entries they publish.

Run the following command and follow the instructions in your terminal:

./mvnw com.gradle:gradle-enterprise-maven-extension:provision-access-key

Note

For more ways to authenticate, see the authentication guide to see how to provide credentials.

  1. Notice how pom.xml filters the build timestamp into src/main/resources/build-info.properties, this will create a build cache miss.

Tip

This lab focuses on, running the Build Validation Scripts. We go into more detail on how to normalize (workaround) this type of build cache miss in the Build Cache Deep Dive course.

  1. Set shell variables to containing the version and checksum:

    version="2.5.1"
    # You can find the SHA 512 checksum on the releases page:
    # https://github.com/gradle/gradle-enterprise-build-validation-scripts/releases
    checksum="131fb1a0de2409d7f1747bd0da75680e757d791596a81f43787f36badf40f1385aa593ab053c1b396a1bcbf6b9da64cc355e78c04eb55ff5d0a6526a5f318e54"

Note

As of this writing the version of the Build Validation Scripts is 2.5.1, check the Build Validation Scripts repository for the latest version.

  1. Download and extract the build validation scripts zip file:

    # Download and extract in temp directory
    pushd /tmp
    # Download scripts zip
    curl -s -L -O "https://github.com/gradle/gradle-enterprise-build-validation-scripts/releases/download/v${version}/gradle-enterprise-maven-build-validation-${version}.zip"
    # Verify zip
    echo "${checksum}  gradle-enterprise-maven-build-validation-${version}.zip" | shasum -a 512 -c-
    # Extract Build Validation Scripts
    unzip -q -o gradle-enterprise-maven-build-validation-${version}.zip
    popd
  2. Execute the build validation script to run two build in different directories:

    /tmp/gradle-enterprise-maven-build-validation/02-validate-local-build-caching-different-locations.sh \
      --git-repo "$(pwd)" \
      --goals verify \
      --fail-if-not-fully-cacheable

    After both builds finish you will see Summary and Investigation Quick Links sections, click on the "Goal inputs comparison" link, to view the differences in the inputs. Notice that the build-info.properties file is different.

    input-comparison.png)

  3. See the .github/workflows/cron-shell-script.yml to automate this process.

Note

The above cron-shell-script.yml, performs each of the steps mentioned above to demonstrate how these steps could be run on any CI system. If you are using GitHub Actions, these steps can be simplified by using a shared Action, see .github/workflows/cron-shared-action.yml

  1. To see how to work around the build cache miss, see the commented out section in this project's pom.xml, or see the dedicated lab.

More Free Labs & Courses

Be sure to check out our other free courses and labs!

Related courses:

Related labs:

About

DPE University Lab: Learn how to keep your projects build cache optimized with the Build Validation Scripts

Topics

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Languages