Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Pipeline disregards use of maven cache

Andrius Karpavičius
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 24, 2025 edited

Here is our pipeline definition.

When running, I see that maven dependencies are downloaded on every run even pipeline is configured to use maven cache.

 

 

image: maven:3.9-eclipse-temurin-21

clone:
  depth: full              # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - maven
          - sonar
        script:
          - mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
        artifacts:
          - target/**
    - step: &mirror-to-github
        name: Mirror to Github
        script:
          - git push --mirror git@github.com:{account}/{repo}.git

pipelines:                 # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
  custom: # Pipelines that can only be triggered manually
    sonar:
      - step: *build-test-sonarcloud
  branches:
    '{dev,*.X,*-sonar-*}':
      - step: *build-test-sonarcloud
    'release/*':
      - step: *build-test-sonarcloud
      - step: *mirror-to-github
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

 

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 25, 2025

Hi Andrius and welcome to the community!

There are a few things to check:

First, open the Pipelines page of the repo on Bitbucket's website. On this page, you will see a button named Caches near the top right corner (between the buttons Schedules and Usage). If you select the Caches button, do you see the maven cache listed?

 

If you don't see the maven cache listed there:

Open the page of a recent successful Pipelines build (cache is only generated on successful builds) that should generate this cache.

Select the step that should generate the cache, and then in this step's build log expand the Build teardown section.

What messages do you see there about the maven cache? Only caches under 1GB once compressed are saved. If your cache is larger than 1 GB or if there's any other issue (e.g. the cache directory is empty), there should be a message about it in the Build teardown section.

If you see a message about an empty cache, you can add the command ls -lahR ~/.m2/repository in the beginning and in the end of the script in the step that generates this cache to double check if it's empty. You will then need to check your build configuration and see if your dependencies are perhaps downloaded in a different directory (the directory ~/.m2/repository is used for the default maven cache in Pipelines).

Please also keep in mind that caches get removed one week after they are generated, but they should be repopulated on the next successful build.

If you see the maven cache listed there:

Have your project's dependencies perhaps changed since the cache was generated? I see in your bitbucket-pipelines.yml file that you are using static directory caching, and the cache doesn't get updated in this case if your dependencies change.

You can use a custom cache with file-based cache keys, so that a new cache gets generated when the file with your project dependencies gets updated:

 

Just a heads up, I edited the repo details from your yml to protect your privacy.

Please feel free to let me know your findings and if you have any questions.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events