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 add build cache support to any Maven plugin.
- Finished going through the Caching for Other Plugins section in Maven Build Cache Deep Dive.
- Java 11+
-
View the
pom.xml
, pay attention to theexec-maven-plugin
and the command executes a command similar to this:# Change directory to target/ cd target/ # read the contents of a file, assign it to shell variable `person` person=`cat ../name.txt` # write `hello $person` to the file `hello.txt` echo "hello $person" > hello.txt
From the root directory, you can think of this script as having the input of
name.txt
and an output oftarget/hello.txt
-
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:
```shell
./mvnw com.gradle:develocity-maven-extension:provision-access-key
```
Note
For more ways to authenticate, see the authentication guide to see how to provide credentials.
-
Enable the build cache debug logging to view additional details:
export MAVEN_OPTS="-Dorg.slf4j.simpleLogger.log.develocity.goal.cache=debug"
-
Execute the build:
./mvnw clean verify
-
Create a
pluginManagement
section in thepom.xml
.
Note
The free build cache training course walks through the following steps in detail.
-
Add the
develocity-maven-extension
topluginManagement
. -
Add a configuration entry for the
exec-maven-plugin
. -
Set a value for the
cacheableBecause
argument. -
Add the
name.txt
file as an input. This is similar to what you did in the missing inputs lab. -
Define the
hello.txt
file as an output. -
Run the build:
./mvnw clean verify
-
Scroll back to the
exec-maven-plugin
in the console output, and note the log message, stating caching was not enabled for this goal (this message can also be viewed in the Build Scan). -
Add the missing parameters as inputs.
Note
If you are familiar with the plugin, you can walk through configuring each argument, adding or ignoring each one. In this lab we will iteratively run the build do demonstrate the types of error you may see when enabling build caching for other plugins.
- Run the build:
./mvnw clean verify
-
Once again, scroll back in the console or view the Build Scan to see the reason why the build was not cached.
-
Configure the extension to ignore the file parameters (
workingDirectory
,buildDirectory
, andbasedir
) as they are not used in this use case (e.g. we are explicitly configuring each of the input and output files). -
Run the build:
./mvnw clean verify
-
Again, scroll back in the console (or view the Build Scan). Note that one of the input types is unsupported. For this use case, the
project
,pluginDependencies
, andsession
, can all be ignored (as we are concerned with only the script execution). -
Configure the
skip
property. Remove theskip
property as an input, and define askipIfTrue
section in the configuration. -
Run the build multiple times:
./mvnw clean verify
The goal is now cachable! Open the Build Scan to view its details.
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: