How to cache Gradle dependencies




  1. Put the Cache:Pull step after the Git Clone step
  2. Put the Cache:Push step to the very end of the Workflow

If you use v1.0 or newer of the Cache steps and the latest Gradle Runner step then that’s all you have to do.

If you use an older Cache or Gradle Runner step:

  1. Select the Cache:Push step and specify the following paths for caching (Cache paths input):
  2. Select the Cache:Push step and specify the following paths for update-check ignore (Ignore Paths from change check input):

Example workflow

  - git-clone: {}
  - cache-pull: {}
  - gradle-runner:
      - gradle_file: "$BITRISE_PROJECT_PATH"
      - gradle_task: "$GRADLE_TASK"
  - cache-push:
      - cache_paths: |-
      - ignore_check_on_paths: |-

For more information about the Bitrise Build Cache see the DevCenter.

Android build and gradle
Could not resolve all files for configuration ':classpath'
Could not resolve all files for configuration

Hi Viktor,
I encounter an issue with the Cache:Pull step, the step seems failed to download or extract the cache archive, it produce this log

2017/09/28 04:19:46 => > Downloading and extracting cache archive …
2017/09/28 04:19:46 [!] Unable to download or uncompress cache: failed to extract tar archive, output: gzip: stdin: not in gzip format
tar: Child died with signal 13
tar: Error is not recoverable: exiting now, error: exit status 2, retrying…
2017/09/28 04:20:33 => [DONE]
2017/09/28 04:20:33 => Took: 47.71805638s
2017/09/28 04:20:33 => Finished

I’ve checked the Cache:Push step from the previous build and it finished successfully.


Hi @fchristysen,

Can you please create an issue report at #issues:build-issues, or via email or the onsite chat?


Hi, im trying to cache gradle with this below. but it seems it’s not working.
it takes the same amount of time every build.

  - cache-push:
      - cache_paths: |-
      - ignore_check_on_paths: |-

especially i want to cache $HOME/.gradle, which contains local caches of gradle.

does this have something to do with this?


@taku Without more info it’s really hard to say anything useful.

I’d suggest you to upgrade all the related steps in the workflow, and if that wouldn’t help please create a #issues:build-issues report so that we’ll have enough info to debug it :wink:


sorry, i figured it out. it was because PR. PR is not cashed, unless I set run_if: true


Indeed, the Cache:Push step is configured to not to push back cache in case of PR builds. In general we’d suggest you to keep that default behaviour, but of course if you have a use case which requires / benefits from pushing back from pull request builds the run_if: true option can be used :slight_smile:


Hi @viktorbenei, does this eliminate cleanBuildCache or clean in Gradle build?
For example

  • ./graldew clean cleanBuildCache assembleDebug takes 20 mins for my app
  • ./graldew clean assembleDebug takes 10+ mins for my app
  • ./graldew cleanBuildCache assembleDebug takes 10+ mins for my app
  • ./graldew assembleDebug takes <10 mins for my app
    By using these cache-pull and cache-pull steps, what will my build time be?


You have to actually run a build to find out what the build time will be. :wink: I have noticed a good improvement by caching the gradle dependencies.


Hi @viktorbenei

The caching gradle system works fine on my Android project! Thanks!
I would like to know where I can find the logic of Bitrise for detecting when it can re-use the pulled cache or not; I assume it is somewhere in the Steps but I still can’t find it… sorry… :frowning:

What I would like to do is to make sure NOT to re-use the cached data if certain project-specific file in the project(e.g. gradle file) is modified whenever changes are pushed.

Thanks in advance!



Hi, thanks for the question.

I think you should add a script step right after the git-clone step.
This script should decide if the build should use cache or not.
You can use git diff command to determine which files changed. Use envman to export an environment variable which holds if cache is needed or not.

envman add --key USE_CACHE --value "true"

Use this env in the cache step’s run_if property (which controls if the step should run or not), like:

run_if: {{getenv “USE_CACHE” | eq “true”}} `

Let me know if you need any help to implement the script!