EDIT: When I wrote this post, Maven 3.9.x wasn’t available on pulbic release.
This doc is aim to help you use Maven Build Cache. Remember, if you’re not fluent in Maven, you might stop here.
Since Maven-Build-Cache run only with Maven >= 3.9.x we will use the 3.9.x-SNAPSHOT version. So the summed up version this post is:
- Build Maven 3.9.x version
- Add Maven-Build-Cache in you project
- Check if it work
1 – Build Maven 3.9.x version
To build maven from the source, read the documentation: https://maven.apache.org/guides/development/guide-building-maven.html
Sumed-up of the previous doc:
- git clone https://github.com/apache/maven.git
- cd [MAVEN DIRECTORY]
- change branch git checkout maven-3.9.x
- mvn -DdistributionTargetDir=”[DIRECTORY YOU WHANT TO STORE THE BINARY]” install
2 – Add Maven-Build-Cache in you project
First read the doc: https://maven.apache.org/extensions/maven-build-cache-extension/
Sumed-up of build cache doc:
- In your projet add a directory
[YOUR PROJECT]/.mvn - In the previous directory add two files
extensions.xmlandmaven-build-cache-config.xml
maven-build-cache-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<cache xmlns="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/BUILD-CACHE-CONFIG/1.0.0 http://maven.apache.org/xsd/cache-config-1.0.0.xsd">
<configuration>
<enabled>true</enabled>
<hashAlgorithm>XX</hashAlgorithm>
</configuration>
<input>
<global>
<glob>{*.java,*.xml,*.properties}</glob>
</global>
</input>
</cache>
extensions.xml
<extension>
<groupId>org.apache.maven.extensions</groupId>
<artifactId>maven-build-cache-extension</artifactId>
<version>1.0.0-SNAPSHOT</version>
</extension>
3 – Check if it work
Make sure you update you environment variables to use the Maven you just built. On you project run mvn package two times, first time should produce some files into next to your local maven repository ./m2/build-cache/, the second time should work way more fast is you didn’t changed anything into the code.
If you wanna run without changing your environment vars. Assuming you have an JAVA_HOME and MAVEN_HOME as env var, try running this line: # JAVA_HOME="[...]/jdk-XX/ MAVEN_HOME="[DdistributionTargetDir]/" mvn package
This was the minimal you need to make is work, for some information refer to the maintainer documentations: Maven Build Cache, Maven build from sources
Leave a Reply