Skip to content

gradle/dpeuni-maven-build-cache-deep-dive-cache-misses

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!

Maven Build Cache Deep Dive - Lab 04: Handling Cache Misses with Normalization

This is a hands-on exercise to go along with the Maven Build Cache Deep Dive training module. In this exercise you will go over the following:

  • How to deal with cache misses.

The sample code represents a multi-module build. The module build-info generates a file build-info.properties containing the current timestamp and the project version. The module application uses the artifact produced by build-info.

Prerequisites

  • Finished going through the Troubleshooting Build Cache Misses section in Maven Build Cache Deep Dive.
  • Java 11+

Steps

  1. If you have not completed the previous 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 the model build produces a build-info.properties (filtered from src/main/resources).

  2. In application/pom.xml notice that build-info is a dependency for the application module.

  3. Execute the build multiple times and identify the reason why the test goal needs to execute every time with the help of the "Build Comparison" tool in Develocity:

    ./mvnw clean install
  4. Configure the Build Scan to capture the goal inputs.

    Add the following to the .mvn/gradle-enterprise.xml:

    <buildScan>
      <capture>
        <goalInputFiles>true</goalInputFiles>
      </capture>
    </buildScan>

Tip

Alternatively, you can enable this setting by adding -Dgradle.scan.captureGoalInputFiles=true to your Maven commands. However, it's usually recommended to enable this for all builds unless you have poor network connection.

  1. Normalize the runtime classpath to ignore unstable input files. See the ignoring arbitrary files guide to see how to normalize the build-info.properties file from the runtime classpath.

Note

The normalization element is a direct child of the gradleEnterprise element.

  1. Execute the build again, at least twice. Verify that there are build cache hits by looking at the Build Scan. Furthermore, check for differences in the build comparison view.

    ./mvnw clean install

Important

Instead if ignoring an entire file, you can instead ignore specific properties. See the free build cache course for a detailed walk through.

Solution Reference

To see the solution to the lab, check out the solution branch of this project.

More Free Labs & Courses

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

Related courses:

Related labs: