Gradle on GitHub Actions
This page is a reference for integrating Gradle with GitHub Actions using the official gradle/actions.
Available actions
The gradle/actions repository publishes three composable actions.
All examples on this page target the current major version, v6.
| Action | Purpose |
|---|---|
Configures the runner for Gradle builds. Restores and saves the Gradle User Home cache, validates the Gradle Wrapper, and captures Build Scan® links in the job summary. |
|
Generates a dependency graph for the project and submits it to the GitHub Dependency Submission API, enabling Dependabot alerts and supply-chain security features. |
|
Validates the checksum of every |
|
|
Configuring builds with setup-gradle
A minimal workflow that builds a Gradle project and publishes a Build Scan:
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- uses: gradle/actions/setup-gradle@v6
with:
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"
- run: ./gradlew build
Key inputs
| Input | Description |
|---|---|
|
Gradle version to provision on the runner. Accepts an explicit version (e.g. |
|
Caching backend. |
|
Set to |
|
Read cache entries but do not write them back. Typical for feature branches so only the default branch updates the cache. |
|
Start with a clean Gradle User Home and save state at job end. Useful for seeding a fresh cache. |
|
Purge unused files from Gradle User Home before saving. One of |
|
Base64-encoded AES key used to encrypt configuration-cache entries, which may contain credentials. Required to cache the configuration cache across jobs. |
|
Glob patterns that add to or subtract from the set of Gradle User Home paths that are cached. |
|
When |
|
Required when |
|
Access key for publishing Build Scans to a private Develocity server. Provide via |
|
Controls the GitHub Actions job summary produced by the action: |
|
Mirror the job summary as a pull-request comment: |
See the setup-gradle documentation for the complete input reference.
Caching behavior
setup-gradle automatically saves and restores the Gradle User Home (~/.gradle), which contains the Gradle distribution, resolved dependencies, and the local build cache.
A cache entry is written at job completion when the job is a push to the default branch; other jobs restore from existing entries.
Starting with version 6.1.0, the default cache backend is the enhanced provider, which offers higher hit rates than the standard GitHub Actions cache.
Set cache-provider: basic to use the fully open-source implementation over actions/cache.
Submitting dependency graphs
The dependency-submission action runs the Gradle build in a dedicated mode that captures the resolved dependency graph, then submits it to GitHub via the Dependency Submission API.
Once submitted, the graph powers Dependabot alerts and the Insights → Dependency graph view.
name: Dependency Submission
on:
push:
branches: [main]
permissions:
contents: write
jobs:
dependency-submission:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- uses: gradle/actions/dependency-submission@v6
with:
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"
|
The workflow requires |
Key inputs
| Input | Description |
|---|---|
|
What to do with the generated graph: |
|
If |
|
Regex filters on Gradle subproject paths, e.g. |
|
Regex filters on configuration names, e.g. exclude |
|
Task used to resolve dependencies. Defaults to the built-in |
|
Extra arguments appended to the Gradle invocation (for example |
|
Path to the Gradle build if it is not at the repository root. |
|
Retention for uploaded dependency-graph artifacts (default |
See the dependency-submission documentation for the complete input reference.
Validating the Gradle Wrapper
setup-gradle validates every gradle-wrapper.jar in the repository on each run. Projects that do not otherwise use setup-gradle (for example, those building with a pre-installed Gradle distribution) can run the standalone action:
- uses: gradle/actions/wrapper-validation@v6
Build Scans in job summaries
When setup-gradle or dependency-submission detects a published Build Scan, it appends the scan link and a task-execution summary to the GitHub Actions job summary. Use add-job-summary-as-pr-comment: on-failure to surface the same information on the pull request when a build fails.
Matrix builds
For matrix builds, use cache-read-only: true on non-primary matrix legs so only one leg writes to the cache:
strategy:
matrix:
java: [17, 21]
steps:
- uses: gradle/actions/setup-gradle@v6
with:
cache-read-only: ${{ matrix.java != 21 }}