Configuring the Build Cache for Gradle in local environments
You can use the Bitrise Build Cache even for local Gradle builds. In this way your local builds and CI builds will use the same build cache, minimizing build times in both environments.
There are two ways to set up the Bitrise Build Cache for a Gradle project:
-
Configuring caching in a separate file, without changing Gradle project files.
-
Configuring caching directly in the Gradle project build files.
If you want to get started with the Bitrise Build Cache without changing the project's build configuration (and affecting others working on the same project), you can do so with a Gradle init script.
-
Generate a Personal Access Token on Bitrise: Creating a personal access token.
Copy the value of the token, as you will need it during the process.
-
Find your Workspace ID: open the Workspace settings page and select General settings on the left navigation menu. You can find and copy the slug from there.
-
Set the following Environment Variables in your CI configuration:
-
BITRISE_BUILD_CACHE_AUTH_TOKEN
: The value should be your Personal Access Token. -
BITRISE_BUILD_CACHE_WORKSPACE_ID
: The value should be the Bitrise Workspace slug.
-
-
Download the CLI and install it in a temporary location. You will only need to use it to activate the build cache once, or if any of the settings change.
curl --retry 5 -sSfL 'https://raw.githubusercontent.com/bitrise-io/bitrise-build-cache-cli/main/install/installer.sh' | sh -s -- -b /tmp/bin -d
-
Activate the Bitrise Build Cache.
There are a couple of flags you can use to control the configuration, but we recommend these defaults:
/tmp/bin/bitrise-build-cache activate gradle --cache --cache-push=false
Pulling from cache
We recommend only pulling artifacts from the cache to avoid accidentally sharing incorrect cache data due to file modifications during a build.
For the full list of flags check the CLI’s
/tmp/bin/bitrise-build-cache activate gradle --help
command.
Now Bitrise Build Cache will be used for your local builds. You can check the invocation details through the link printed during builds:
