I have a pipeline that does a Maven install, and then a SonarCloud analysis using Maven. I have a m2 repository cache configured in the pipeline. I see the cache being used during the Maven install, but not in the Maven SonarCloud analysis. This is constant after three builds.
I have a private Nexus repository where dependencies are downloaded.
The cache is configured as follows:
definitions:
caches:
custom-maven:
key:
files:
- pom.xml
path: /usr/share/maven/ref/repository
The Maven install step is as follows:
- step: &build-test
name: Build & test
caches:
- custom-maven
script:
- mvn -B -T2C install -s ./settings.xml
artifacts:
- target/*.jar*
The SonarCloud analysis:
- step: &sonarcloud
name: Static code analysis using SonarCloud
image:
name: [some private image]
username: $DOCKER_USERNAME
password: $DOCKER_PASSWORD
caches:
- custom-maven
- custom-sonar
script:
- mvn -B -T2C verify sonar:sonar -s ./settings.xml
The (I think) relevant bit from settings.xml:
<localRepository>/usr/share/maven/ref/repository</localRepository>
The logs of the Maven install:
+ mvn -B -T2C install -s ./settings.xml
[INFO] Scanning for projects...
[INFO]
[INFO] Using the MultiThreadedBuilder implementation with a thread count of 8
[INFO]
[INFO] ----------------------< package:artifact >----------------------
[INFO] Building artifact 1.2.3.BUILD-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
The logs of the SonarCloud analysis:
+ mvn -B -T2C verify sonar:sonar -s ./settings.xml
[INFO] Scanning for projects...
...
many more downloads
...
[INFO]
[INFO] Using the MultiThreadedBuilder implementation with a thread count of 8
[INFO]
[INFO] ----------------------< package:artifact >----------------------
[INFO] Building artifact 1.2.3.BUILD-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
The cache is available when I look in the Bitbucket UI:

What I want is for the caching to work during the SonarCloud analysis as well. What is going on here? What can I do to fix this?