Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Maven cache sometimes not working

Mark Gortzak August 9, 2023

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:

cache.png

 

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?

2 answers

1 accepted

0 votes
Answer accepted
Mark Gortzak August 15, 2023

I talked with support, the cache is being used. The build time is faster. Maven seems to sometimes/always download certain dependencies. This might be a problem with our Maven configuration. So it has nothing to do with Bitbucket.

0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 10, 2023

G'day, @Mark Gortzak 

We require to review your pipeline build to investigate the issue further. Since an in-depth investigation is required, I have proceeded to raise a support ticket on your behalf.

Please find your ticket at our support portal:

https://support.atlassian.com/requests/ 

Regards,
Syahrul

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events