Skip to content
Advertisement

Cache Maven dependencies in Tekton Maven Task from Tekton Hub

We want to build a Spring Boot-based project using Maven. We found the Maven Task on the Tekton Hub and already have a running Pipeline. In a shortened version our pipeline.yml looks like this:

JavaScript

And a PipelineRun is defined as:

JavaScript

The source-pvc PersistentVolumeClaim is defined as:

JavaScript

Our project is being build fine, but the Task downloads all the project’s Maven dependencies over and over again when we start another PipelineRun:

enter image description here

The Tekton Hub’s Maven Task https://hub.tekton.dev/tekton/task/maven doesn’t seem to support using a cache. How can we cache nevertheless?

Advertisement

Answer

There’s an easy way to accomplish caching using Tekto Hub’s Maven Task. Instead of specifying an empty directory in the maven-settings workspace with emptyDir: {} you need to create a new subPath inside your already defined source-pvc PersistentVolumeClaim. Also link the persistentVolumeClaim the same way as you already linked it for the source-workspace. Your PipelineRun now somehow looks like this:

JavaScript

Now the new subPath is already available via the maven-settings workspace inside the Tekton Hub’s Maven Task (which doesn’t implement an extra cache workspace right now). We only need to tell Maven to use the path workspaces.maven-settings.path as the cache repository.

Therefore we add -Dmaven.repo.local=$(workspaces.maven-settings.path) as a value to the GOALS parameter of the maven Task like this:

JavaScript

Now after the first pipeline execution every next run should re-use the Maven repository inside the maven-settings workspace. This should also prevent the log from beeing polluted with Maven Download statements and speeds up the pipeline depending on the number of dependencies:

enter image description here

Our simple example builds more than twice as fast.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement