Skip to content

gradle/dpeuni-maven-build-cache-deep-dive-getting-started

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 01: Getting Started

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 use a local build cache to speed up a Maven Build.
  • Adding the Develocity Maven Extension to a project.
  • Basic usage of a build cache.

Prerequisites

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

Steps

  1. Apply the latest version of the Develocity Maven Extension to the project.

    Run the command:

    ./mvnw com.gradle:gradle-enterprise-maven-extension:1.20.1:init \
      -Dgradle.enterprise.url=https://dpeuniversity-develocity.gradle.com

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.

See the getting started guide for details.

  1. Create an access key to access the Develocity server.

    Run the command:

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

Tip

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

  1. Configure the project to only use the local build cache. Disable the remote build cache. See how to set up gradle-enterprise.xml in the getting started guide.

  2. Ensure local cache doesn't exist. Best way to do this is to delete ~/.m2/.gradle-enterprise/build-cache

    rm -rf ~/.m2/.gradle-enterprise/build-cache
  3. Build and run the application with local caching enabled. Enable debug logging for the build cache to see the details. The command is:

     ./mvnw clean verify exec:java -Dorg.slf4j.simpleLogger.log.gradle.goal.cache=debug

    On the first run, the build cache directory is created and populated with the outputs of the compilation operation. Identify the relevant log outputs.

  4. Run again without changes. The log output contains two messages that indicated that the outputs were pulled from the cache. What would happen if you ran the same command multiple times?

  5. What behavior would you expect if you deleted the directory ~/.m2/.gradle-enterprise/build-cache and re-ran the same command.

  6. Configure the local cache to a non-standard directory and set the number of days that unused entries will be garbage collected to 30 days.

    • See the local cache configuration guide to set the directory. You can simply set it to build-cache which will create the cache directory in the current project.
    • See the local cache cleanup guide to set the cleanup retention and interval values.

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: