Configuring the build cache for Gradle in local builds
You can use the Bitrise Build Cache for local Gradle builds too. Your local builds then read from the same cache as your CI builds, so a task your CI already compiled doesn't have to be compiled again on your machine.
The Bitrise Build Cache CLI sets this up for you. It writes a Gradle init script to ~/.gradle/init.d/, so your project files stay untouched.
You can also set this up with an AI coding agent instead of following the steps manually. See Getting started with AI.
Before you startClick to copy link
Ensure you have:
- A working Gradle project on your machine (macOS or Linux).
- A Bitrise workspace with the Build Cache enabled. Check it on the Build Cache page.
- Network access to the Bitrise hosts the Build Cache uses, if your machine is behind a VPN, a firewall, or an outbound proxy. See Network endpoints for firewalls and VPNs.
If your project builds C/C++ code (NDK, JNI, or native modules), set up ccache alongside Gradle. The Gradle plugin caches Java and Kotlin task outputs, but native compiles bypass it and go through ccache instead. Install it with brew install ccache, then select both Gradle and ccache (C/C++) in the wizard.
Installing the CLIClick to copy link
Install the CLI with Homebrew (recommended):
brew install bitrise-io/bitrise-build-cache/bitrise-build-cache
Or, without Homebrew:
curl --retry 5 -sSfL \
'https://raw.githubusercontent.com/bitrise-io/bitrise-build-cache-cli/main/install/installer.sh' \
| sh -s -- -b ~/.local/bin
Make sure the install location is on your PATH, then check the install:
bitrise-build-cache --version
Activating the cacheClick to copy link
Run the interactive wizard:
bitrise-build-cache activate --interactive
The wizard asks for the following:
- Sign in to Bitrise: opens your browser for authentication on the first run. The CLI stores the credentials in the OS keychain and refreshes them automatically, so later runs skip this step. On a machine without a usable keychain, the CLI falls back to storing them in a config file.
- Select a workspace: pick the workspace whose Build Cache you want to use. The CLI selects it automatically if you only have access to one.
- Which build tools should I set up: ensure Gradle is selected, plus ccache (C/C++) if your project builds native code. Use space to toggle an option and enter to confirm.
- Display name for this machine's local invocations: the name your local builds show up under in the Build Cache dashboard, for example
local-<yourhandle>. - Enable cache push: keep the default Yes, push too. See Cache push mode.
- Keep the cache proxies running in the background: select Yes, install + start if you set up
ccache. This registers the helper processes with the OS so they survive shell restarts.
If BITRISE_BUILD_CACHE_AUTH_TOKEN and BITRISE_BUILD_CACHE_WORKSPACE_ID are already set in your shell, the CLI uses those instead of the stored credentials. Unset them if you want the sign-in to apply.
Verifying the setupClick to copy link
Run the CLI's health check:
bitrise-build-cache doctor
It reports the status of every part of the local setup — credentials, backend connectivity, helper processes, and log directories — and ends with an overall verdict:
Bitrise Build Cache - doctor
CLI version: 3.x.y
Healthy:
✓ auth OAuth login (keychain) (workspace <id>), token valid until <iso-timestamp>
✓ keychain-smoke Set/Get/Delete round-trip OK
✓ auth-backend latency <ms>, source=keychain, workspace=<id>
✓ ccache-binary found at /opt/homebrew/bin/ccache
✓ ccache-helper running (~/.local/state/ccache/ccache.sock)
✓ log-dirs all log dirs present + writable
Overall: ok
To let the CLI repair the issues it can fix on its own, run bitrise-build-cache doctor --fix --interactive.
Running a buildClick to copy link
-
Clean the project's local build outputs first, so the build has to fetch from the remote cache. Pass
--no-daemonas well: a Gradle daemon started before the activation doesn't pick up the new configuration.cd path/to/your/gradle/project./gradlew clean --no-daemon -
Run the build:
./gradlew :app:assembleDebug
A build that hits a warm cache ends like this:
> Task :app:compileDebugKotlin FROM-CACHE
> Task :feature:one:compileDebugKotlin FROM-CACHE
BUILD SUCCESSFUL in 18s
149 actionable tasks: 71 executed, 78 from cache
[Bitrise Analytics] 155 tasks uploaded. Check invocation at
https://app.bitrise.io/build-cache/invocations/gradle/<uuid>
Checking that it workedClick to copy link
| Signal | Where to find it | What success looks like |
|---|---|---|
Task :module:name FROM-CACHE | Gradle build output, per task | The task line ends with FROM-CACHE |
N actionable tasks: X executed, Y from cache | Gradle build summary | A non-zero from cache count |
| Invocation link | Printed at the end of the build | Opens the per-task metrics for the build |
| Dashboard | Build Cache page | A row appears under your display name |
| Init script | ~/.gradle/init.d/bitrise-build-cache.init.gradle.kts | The file exists and contains buildCache { |
Cache push modeClick to copy link
The setup in this guide activates the Build Cache with cache push enabled: your local builds read from and write to the shared cache. Every task your machine builds becomes an entry your teammates and CI can reuse, and your activity shows up on the Build Cache page.
If you'd rather have your local builds only read from the cache, see Opting into pull-only mode below.
Opting into pull-only modeClick to copy link
If your team already populates the cache from CI and you want your local builds to only read from it, turn cache push off. The trade-off is that your local builds contribute nothing, so if CI doesn't run yet the summary line stays at 0 from cache.
Re-run bitrise-build-cache activate --interactive and answer No, pull only at the cache push prompt, or run the non-interactive activate command:
bitrise-build-cache activate gradle --cache --cache-push=false
If a build doesn't behave as expected, re-run the activation with debug logging:
bitrise-build-cache activate gradle --cache --cache-push=false --debug
TroubleshootingClick to copy link
Start with the CLI's health check. It inspects every part of the local setup and repairs the issues it can fix on its own:
bitrise-build-cache doctor --fix --interactive
If you're still experiencing issues, check the following table:
| Issue | Fix |
|---|---|
| The wizard reports that it needs a terminal | Run TERM=dumb bitrise-build-cache activate --interactive for line-based mode. |
doctor reports a problem it can't fix | Re-run it with --debug for the full context. |
| Your build ignores the new configuration | Stop any running Gradle daemons with ./gradlew --stop, or pass --no-daemon. |
| You want to start over | It's safe to re-run the wizard. It re-reads the current state and applies the same activation again. |
| The build can't reach the cache, or the cache calls time out | Your VPN, firewall, or proxy may block the Bitrise hosts. Check them against Network endpoints for firewalls and VPNs. |