Checkout all the free Maven, Gradle, and DPE courses at the DPE University!
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.
- Finished going through the Local Build Cache section in Maven Build Cache Deep Dive.
- Java 11+
-
Apply the latest version of the Develocity Maven Extension to the project.
Run the command:
./mvnw com.gradle:develocity-maven-extension:1.21.4:init \ -Ddevelocity.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.
-
Create an access key to access the Develocity server.
Run the command:
./mvnw com.gradle:develocity-maven-extension:1.21.4:provision-access-key
Tip
For more ways to authenticate, see the authentication guide to see how to provide credentials.
-
Configure the project to only use the local build cache. Disable the remote build cache. See how to set up
develocity.xml
in the getting started guide.- See the configuring the local cache guide to configure local cache. (Enabled by default)
- See the disabling the remote cache guide to disable the remote cache.
-
Ensure local cache doesn't exist. Best way to do this is to delete
~/.m2/.develocity/build-cache
rm -rf ~/.m2/.develocity/build-cache
-
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.develocity.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.
-
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?
-
What behavior would you expect if you deleted the directory
~/.m2/.develocity/build-cache
and re-ran the same command. -
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
andinterval
values.
- See the local cache configuration guide to set the directory. You can simply set it to
To see the solution to the lab, check out the solution
branch of this project.
Be sure to check out our other free courses and labs!
Related courses:
- Maven - Build Cache Deep Dive
- Maven - Maintaining an Optimized Build Cache
- Develocity - How to Use Build Scans
Related labs: