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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,713
Community Members
 
Community Events
176
Community Groups

What is the proper way to use a Maven cache in a muilt-step build?

I have a Bitbucket pipeline that runs Maven several times in several steps. However, it appears that most (all?) of what is needed by Maven misses the cache no matter how many times I run the build within the week. I'm hoping that the issue is one of my misunderstanding on how to use the cache. What is the proper way to use a Maven cache in a muilt-step build?

Note: this is NOT a multi-module Maven build (in case that makes a difference)

Additional Question: Does the cache get updated with additional dependencies throughout the build or does it only get picked up for one of the steps?

This is an example of one of my pipelines that exhibits the behavior (the paste into this editor ate the formatting, so I apologize if there's some mis-aligned whitespace invalidating the YAML).

definitions:
  steps:
    - step: &build-test
      name: Build and Test
      caches:
        - maven
      script:
        - mvn verify

pipelines:
  default:
    - step: *build-test

branches:
  master:
    - step:
      name: Set Version and Environment
      caches:
        - maven
      script:
        - >
          mvn build-helper:parse-version versions:set
          -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}-${BITBUCKET_BUILD_NUMBER}
        - >
          echo "export VERSION=$(mvn help:evaluate
          -Dexpression=project.version
          -q -DforceStdout)" > version
      artifacts:
        - pom.xml
        - version

    - step:
      name: Build, Test, Package, and Publish
      caches:
        - maven
      script:
        - source ./version
        - mvn verify

    - step:
      name: Update Versions and Push
      caches:
        - maven
      script:
        # Commit and tag the built release version
        - mvn scm:add@add scm:checkin scm:tag@tag -Dscm=rel

        # Set the new development version

        - >
          mvn build-helper:parse-version versions:set
          -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}-SNAPSHOT

        # Commit the new development version
        - mvn scm:add@add scm:checkin -Dscm=dev

pull-requests:
  '**':
    - step:
      <<: *build-test
      after-script:
        - pipe: atlassian/checkstyle-report:0.3.0

1 answer

0 votes
Mark C Atlassian Team Apr 18, 2022

Hi @Joshua Tharp

Thank you for reaching out to the community.

To answer your question, a Cache will only be uploaded once in a step.
Unfortunately, it's not get updated in the succeeding steps.

We do have an existing feature request for it to refresh Cache dependencies when gets updated that can be located through this link. - https://jira.atlassian.com/browse/BCLOUD-16314
You can upvote and watch it for now so that you'll be notified of any updates from our team when the feature becomes available on Bitbucket Cloud.
Please do note that we don't have an exact ETA for the feature request as all new features will be implemented according to our policy here.

As a workaround, you can refresh your cache by clearing it in a step by the use of a Pipes script called atlassian/bitbucket-clear-cache.

script:
  - pipe: atlassian/bitbucket-clear-cache:3.1.1
    variables:
      BITBUCKET_USERNAME: $BITBUCKET_USERNAME
      BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD
      CACHES: ["maven", "node"]

Hope it helps and do let me know if you have further questions that I can help with.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events