Project Setup: Gradle
Configuring your Gradle build for remote caching with Buildless
Setting up your Gradle project with Buildless is very easy once your API key is installed. You can use the Buildless Plug-in for Gradle, or you can configure Gradle manually.
First up: Enable the cache
Whether you're using the plug-in or the manual configuration route, make sure you activate the build cache:
org.gradle.caching = true
./gradlew --build-cache ...
You have to do this part lol
Gradle won't cache anything if you don't specify the
org.gradle.caching
setting. You can do so viagradle.properties
,~/.gradle/gradle.properties
, or via the command lineYou can easily disable the cache if needed by passing
--no-build-cache
Using the Gradle Plugin
Installing the plug-in
The plug-in ID is build.less
, and it is installed as a settings-time plugin. This is important; it means the plug-in can configure your build cache settings for you, and these settings typically reside in your settings:
Latest plugin version: 1.0.0-rc2
plugins {
id("build.less") version "1.0.0-rc2"
}
buildless {
// settings go here (this block is optional; the plugin will detect your API key, if set)
}
plugins {
id 'build.less' version '1.0.0-rc2'
}
buildless {
// settings go here (this block is optional; the plugin will detect your API key, if set)
}
It goes in your Gradle settings
Make sure you install the plug-in in your
settings.gradle
orsettings.gradle.kts
, otherwise it won't be able to configure your build cache for you.
The easiest way to configure your build cache is via the open source Buildless Plug-in for Gradle. The plug-in supports several features which are unavailable when configuring build caching manually.
The plug-in is designed to be largely inert in your codebase; it doesn't change how you build your code, but rather just configures Gradle with the details it needs to easily enable caching:
Finding the latest plug-in version
The latest plug-in version is available on the Gradle Plug-in Portal. Installation instructions are listed in the README of the Plug-in Repo.
Link | Best for |
---|---|
Gradle Plug-in Portal | Finding the latest plugin version, classpath installation instructions |
Plug-in repo on GitHub | Filing issues, asking questions, forking/customizing the plugin |
Without the Plugin: Configuring Gradle manually
Alternatively, if you'd rather not use the plug-in, you can configure Gradle using the main Buildless remote endpoint:
// ...
buildCache {
remote<HttpBuildCache> {
url = uri("https://gradle.less.build/cache/generic/")
credentials {
username = "apikey"
password = System.getenv("BUILDLESS_APIKEY") // or however you'd like to pass your key
}
}
}
// ...
buildCache {
remote(HttpBuildCache) {
url = 'https://gradle.less.build/cache/generic/'
credentials {
username = 'apikey'
password = System.getenv("BUILDLESS_APIKEY") // or however you resolve your key
}
}
}
You may miss out on important features
The plug-in is designed to add very little overhead to your build. For now, it doesn't do much more than the above manual snippet, but later, it will perform several important functions:
- Linking builds to source control: Integration with Git, GitHub, and GitLab will need this
- Optimized client-side routing & balancing: The plug-in will select optimized endpoints for your build cache, based on where your build runs
- Optimized upload choices: The plug-in will deactivate cache pushes if your upload speed isn't optimal for pushing to the cache.
These quality-of-life enhancements are highly recommended for a good cache experience with Gradle.
Updated 12 months ago
🚀 That's it! Your project is ready to go. Check out these links next to continue setting up Buildless for Gradle