Gradle caches not restored to expected location
Asked by Anders Sveen:

I am setting up a gradle cache to enable faster builds. It *seems* (they are listed under caches as well) the cache is stored, but I really can't find the restored cache when running subsequent steps.

How can this be? The build setup outputs even says it downloads the cache and unpacks it.

My setup is something like this:

```
pipelines:
  default:
    - parallel:
        - step:
            name: Build and Test
            caches:
              - gradle
              - gradlewrapper
            script:
              - export TESTCONTAINERS_RYUK_DISABLED=true
              - ls -lah
              - ./gradlew --build-cache --no-daemon stage
            services:
              - docker
            after-script:
              - pipe: atlassian/checkstyle-report:0.2.0
        - step:
            name: Security Scan
            script:
              # Run a security scan for sensitive data.
              # See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
              - pipe: atlassian/git-secrets-scan:0.4.3
    - step:
        name: Build and publish docker image
        size: 2x
        caches:
          - docker
          - gradle
          - gradlewrapper
        script:
          - *docker_build_variables_anchor
          - ls -lah .
          - docker build -t $IMAGE_NAME .
          - docker tag $IMAGE_NAME $IMAGE:master
          - docker push $IMAGE_NAME
          - docker push $IMAGE:master
        services:
          - docker

```

```
definitions:
  caches:
    gradlewrapper: ~/.gradle/wrapper
```

The "ls -lah ." steps above shows no ".gradle" folder on the paths. Even though the build setup for each steps says this:

    Cache "docker": Downloading
    Cache "docker": Downloaded 623.7 MiB in 7 seconds
    Cache "docker": ExtractingCache "docker": Extracted in 7 seconds
    Cache "gradle": Downloading
    Cache "gradle": Downloaded 190.9 MiB in 2 seconds
    Cache "gradle": Extracting
    Cache "gradle": Extracted in 2 seconds
    Cache "gradlewrapper": Downloading
    Cache "gradlewrapper": Downloaded 196.1 MiB in 3 seconds
    Cache "gradlewrapper": Extracting
    Cache "gradlewrapper": Extracted in 1 seconds

Am I misundestanding where the folders should end up? Thanks...


Answers:
author: Anders Sveen
body: From messing around a bit, it seems the gradlewrapper cache is working in the first step (it doesn't re-download when starting). So something is working. How does it find the distrubution without the .gradle/wrapper folder existing?

comments: author: Alan Guerin
body: [@Anders Sveen](/t5/user/viewprofilepage/user-id/4146151) - I'm having a similar issues, and I've tried a number of things to try to work around this without success. I've raised a support issue with Atlassian, and will update here when/if they respond.


author: Alan Guerin
body: [@Anders Sveen](/t5/user/viewprofilepage/user-id/4146151) - After a few more attempts to resolve this, purging the existing caches seems to have fixed it. Go to Pipelines \> Caches (top right of screen), and delete the dependency caches. Re-run your pipeline, and the caching should work.


Tags: bitbucket-cloud

cloud