maven cache in pipeline seems not working
Asked by Zhenguo Li:

I have added below script in pipeline, but it seems not working , every build take more than 30 min for mvn install , any problem recently for this cache function ?

```
image: maven:3.6.3

pipelines:

  branches:
    develop:
      - step:
          name: Build and Unit Test
          artifacts:
            - x_api/target/x_api.jar
            - checkstyle-result.xml
          image: maven:3.6.3
          caches:
            - maven
          script:
            #- mvn -B verify --file pom.xml
            - cd x_api
            - mvn install
            - mvn package --batch-mode
            - cd ../x_service
            - mvn install
            - mvn package --batch-mode
```

thank you,

Jonas


Answers:
author: Theodora Boudale
body: Hi Jonas,

I just wanted to let you know that we have a limit of 1GB for caches, only caches under 1GB once compressed are saved.

Maven cache is saved in the directory **\~/.m2/repository**, so I would suggest checking the size of this directory during the build and after dependencies are downloaded.

If the repo belongs in a workspace with a paid billing plan (I see you are an admin of such a workspace), you can also create a ticket with the Bitbucket Cloud support team to look into this and confirm if the issue is with the cache size or something different. You can create a support ticket via <https://support.atlassian.com/contact/#/>, in "What can we help you with?" select "Technical issues and bugs" and then Bitbucket Cloud as product.

Kind regards,  
Theodora

comments: author: Zhenguo Li
body: thank you Theodora for guide , I submitted a ticket to see if any solution.


author: Theodora Boudale
body: You are welcome Jonas, please feel free to reach out if you ever need anything else.

Kind regards,  
Theodora


author: Zhenguo Li
body: **`I saw below in pipeline log `**

**`Cache "maven": Not found`**

**`is there any limit like size of the maven cache , possible exceed the limit cause maven was not cached`**

comments: author: lissyaka
body: [@Zhenguo Li](/t5/user/viewprofilepage/user-id/4784394) what image do you use? Please provide your full pipeline config and log output  

Also take a look at[this answer](https://stackoverflow.com/questions/54687596/why-bitbucket-pipelines-doesnt-create-cache)


author: Zhenguo Li
body: ```
image: maven:3.6.3

pipelines:

  branches:
    develop:
      - step:
          name: Build and Unit Test
          artifacts:
            - x_api/target/x_api.jar
            - checkstyle-result.xml
          image: maven:3.6.1
          caches:
            - maven
          script:
            #- mvn -B verify --file pom.xml
            - cd x_api
            - mvn install
            - mvn package --batch-mode
            - cd ../x_service
            - mvn install
            - mvn package --batch-mode
```


author: Zhenguo Li
body: i can't paste full log here, it just said there is no cache for maven in build setup step.

and there is no any cache shows if I click the Cache button on pipeline's home page.


author: lissyaka
body: [@Zhenguo Li](/t5/user/viewprofilepage/user-id/4784394). To check if maven cache working or not you should try to run pipeline [this example repo](https://bitbucket.org/bitbucketpipelines/pipelines-guide-java/src/master/)  

If cache is not working its definitely a bug and you may report it.

If cache is working then problem is in your \`script section\`. I think the reason is that you changing folders and then run \`mvn install\` when your cache possibly is in upper folder, but i can be wrong.

Look at [this answer](https://community.atlassian.com/t5/Bitbucket-questions/Pipelines-cache-custom-node-modules-folder/qaq-p/771598) to understand how to define cache for custom folder  

P.S also you do not need

```
image: maven:3.6.1
```

in \`step\` section because you use

```
image: maven:3.6.3
```

in the beginning of your pipeline config. I understand that i suggested you to do it but also it explains why i asked you to provide the full pipeline config to provide better help.  

Cheers


author: lissyaka
body: Hi [@Zhenguo Li](/t5/user/viewprofilepage/user-id/4784394) . At least you should add more details about your pipeline config.  

Also take a look at this answer: [maven cache not working](https://community.atlassian.com/t5/Bitbucket-questions/Maven-cache-not-working-anymore/qaq-p/1307695) .  
There

```
image: maven:3.6.1??
```

was added before caches, maybe this will fix your issue.  

Cheers

comments: author: Zhenguo Li
body: thank you, [@lissyaka](/t5/user/viewprofilepage/user-id/4871214) , but it doesn't work for me .


Tags: bitbucket-cloud

cloud