Compare commits

..
Author SHA1 Message Date
Eric Haag c36ba1fb3d Configure the build cache through Develocity injection
Add setup-gradle inputs that configure the remote and local build cache
through Develocity injection. Each input is passed to the init script as
a DEVELOCITY_INJECTION_* environment variable. The remote build cache
uses the Develocity Build Cache connector.

The develocity-enforce-url description also explains how the enforced
URL applies to a Build Cache connector.
2026-11-18 21:17:15 -06:00
Eric Haag c0152e9a6b Update develocity-injection init script to v2.1 (#1126)
Updates the develocity-injection init script to the latest reference
script content
from https://github.com/gradle/develocity-ci-injection.
2026-11-18 21:12:41 -06:00
Eric Haag db2e964163 Stop expecting a pre-installed JDK 8 in the toolchain detection tests 2026-11-18 20:52:58 -06:00
Eric Haag a9a26ec8ba Provision Java 8 for the init script tests when no local installation exists 2026-11-18 20:52:58 -06:00
Bot Githubaction 2d3f49afd6 Update develocity-injection init script to v2.1
Updates the develocity-injection init script to the latest reference script content
from https://github.com/gradle/develocity-ci-injection.
2026-11-19 01:53:54 +00:00
Iñaki Villar 445a164ce8 Authenticate Develocity injection integ tests with workload identity (#1112)
## Changes

Follow-up to #1109. That PR left `suite-integ-test-other.yml` on
`DV_SOLUTIONS_ACCESS_KEY`.

`integ-test-inject-develocity.yml` now gets a GitHub OIDC token, in
`solutions.develocity.cloud=<token>` form, from the same pre-step as
#1109. The token goes where the access key went before:

- **`inject-develocity`**: the `DEVELOCITY_ACCESS_KEY` /
`GRADLE_ENTERPRISE_ACCESS_KEY` env var, set per matrix entry through
`$GITHUB_ENV`
- **`inject-develocity-with-access-key`**: the `develocity-access-key`
input
- **`inject-develocity-short-lived-token-failed`**: both env vars and
the input
- **`inject-develocity-with-access-key-from-input-actions`**: the
`DEVELOCITY_ACCESS_KEY` env var

setup-gradle exchanges the OIDC token at `/api/auth/token` the same way
it exchanges an access key. The `DEVELOCITY_ACCESS_KEY` secret is
removed from the reusable workflow. `id-token: write` is granted along
the chain: `ci-integ-test*.yml` → `suite-integ-test-other.yml` → the
jobs. Fork PRs are already skipped for these jobs.

Part of gradle/dv#74660. After this merges, nothing in gradle/actions
uses `DV_SOLUTIONS_ACCESS_KEY`.

## Verification

- [ ] CI-integ-test on this PR: `develocity-injection` jobs green, Build
Scans published to solutions.develocity.cloud
2026-11-12 10:53:43 -06:00
Iñaki Villar fac0990588 Bump Gradle Wrapper from 9.9.0 to 9.9.1 in /.github/workflow-samples/java-toolchain (#1123)
Bump Gradle Wrapper from 9.9.0 to 9.9.1.

Release notes of Gradle 9.9.1 can be found here:
https://docs.gradle.org/9.9.1/release-notes.html
2026-11-11 17:39:07 -06:00
Iñaki Villar 5ca09edddf Bump Gradle Wrapper from 9.8.2 to 9.9.1 in /.github/workflow-samples/kotlin-dsl (#1124)
Bump Gradle Wrapper from 9.8.2 to 9.9.1.

Release notes of Gradle 9.9.1 can be found here:
https://docs.gradle.org/9.9.1/release-notes.html
2026-11-11 17:26:08 -06:00
Iñaki Villar a4182520b3 Bump Gradle Wrapper from 9.9.0 to 9.9.1 in /.github/workflow-samples/gradle-plugin (#1121)
Bump Gradle Wrapper from 9.9.0 to 9.9.1.

Release notes of Gradle 9.9.1 can be found here:
https://docs.gradle.org/9.9.1/release-notes.html
2026-11-11 16:50:19 -06:00
Iñaki Villar bfcb30cf34 Bump Gradle Wrapper from 9.9.0 to 9.9.1 in /sources/test/init-scripts (#1120)
Bump Gradle Wrapper from 9.9.0 to 9.9.1.

Release notes of Gradle 9.9.1 can be found here:
https://docs.gradle.org/9.9.1/release-notes.html
2026-11-11 12:42:02 -06:00
bot-githubaction 031d955e6d Bump Gradle Wrapper from 9.8.2 to 9.9.1.
Release notes of Gradle 9.9.1 can be found here:
https://docs.gradle.org/9.9.1/release-notes.html

Signed-off-by: bot-githubaction <[email protected]>
2026-11-11 02:14:00 +00:00
bot-githubaction ee2f5df6fa Bump Gradle Wrapper from 9.9.0 to 9.9.1.
Release notes of Gradle 9.9.1 can be found here:
https://docs.gradle.org/9.9.1/release-notes.html

Signed-off-by: bot-githubaction <[email protected]>
2026-11-11 02:13:09 +00:00
bot-githubaction 15e4fe97d0 Bump Gradle Wrapper from 9.9.0 to 9.9.1.
Release notes of Gradle 9.9.1 can be found here:
https://docs.gradle.org/9.9.1/release-notes.html

Signed-off-by: bot-githubaction <[email protected]>
2026-11-11 02:12:18 +00:00
bot-githubaction c2db668634 Bump Gradle Wrapper from 9.9.0 to 9.9.1.
Release notes of Gradle 9.9.1 can be found here:
https://docs.gradle.org/9.9.1/release-notes.html

Signed-off-by: bot-githubaction <[email protected]>
2026-11-11 02:11:36 +00:00
Iñaki Villar 5a9182793c Bump Gradle Wrapper from 9.8.2 to 9.9.0 in /.github/workflow-samples/gradle-plugin (#1116)
Bump Gradle Wrapper from 9.8.2 to 9.9.0.

Release notes of Gradle 9.9.0 can be found here:
https://docs.gradle.org/9.9.0/release-notes.html
2026-11-10 17:26:16 -06:00
Iñaki Villar b7deba1bb6 Bump Gradle Wrapper from 9.8.2 to 9.9.0 in /.github/workflow-samples/groovy-dsl (#1117)
Bump Gradle Wrapper from 9.8.2 to 9.9.0.

Release notes of Gradle 9.9.0 can be found here:
https://docs.gradle.org/9.9.0/release-notes.html
2026-11-09 18:41:40 -06:00
Iñaki Villar 808476d4c7 Bump Gradle Wrapper from 9.8.2 to 9.9.0 in /.github/workflow-samples/java-toolchain (#1118)
Bump Gradle Wrapper from 9.8.2 to 9.9.0.

Release notes of Gradle 9.9.0 can be found here:
https://docs.gradle.org/9.9.0/release-notes.html
2026-11-09 15:22:45 -06:00
Iñaki Villar 579b122e60 Bump Gradle Wrapper from 9.8.2 to 9.9.0 in /sources/test/init-scripts (#1115)
Bump Gradle Wrapper from 9.8.2 to 9.9.0.

Release notes of Gradle 9.9.0 can be found here:
https://docs.gradle.org/9.9.0/release-notes.html
2026-11-09 14:10:15 -06:00
bot-githubaction e85b2d6f6e Bump Gradle Wrapper from 9.8.2 to 9.9.0.
Release notes of Gradle 9.9.0 can be found here:
https://docs.gradle.org/9.9.0/release-notes.html

Signed-off-by: bot-githubaction <[email protected]>
2026-11-07 02:14:14 +00:00
bot-githubaction d94be6b0be Bump Gradle Wrapper from 9.8.2 to 9.9.0.
Release notes of Gradle 9.9.0 can be found here:
https://docs.gradle.org/9.9.0/release-notes.html

Signed-off-by: bot-githubaction <[email protected]>
2026-11-07 02:13:46 +00:00
bot-githubaction 5fbd536b48 Bump Gradle Wrapper from 9.8.2 to 9.9.0.
Release notes of Gradle 9.9.0 can be found here:
https://docs.gradle.org/9.9.0/release-notes.html

Signed-off-by: bot-githubaction <[email protected]>
2026-11-07 02:13:22 +00:00
bot-githubaction f95d889790 Bump Gradle Wrapper from 9.8.2 to 9.9.0.
Release notes of Gradle 9.9.0 can be found here:
https://docs.gradle.org/9.9.0/release-notes.html

Signed-off-by: bot-githubaction <[email protected]>
2026-11-07 02:12:34 +00:00
Iñaki Villar 96e7f85c08 Inline the OIDC token step and keep the existing assertions
Use the same pre-step as #1109 instead of a composite action, drop the
extra exchange check and the fake access key.
2026-11-05 11:28:41 -06:00
Iñaki Villar f6e4f55eae Test Develocity injection with workload identity instead of an access key
The Develocity injection integration tests no longer use the long-lived
DV_SOLUTIONS_ACCESS_KEY. The jobs that publish Build Scans pass a GitHub
OIDC token as the access key, which setup-gradle exchanges for a
short-lived token like any access key. The short-lived token failure job
uses a fake access key.
2026-11-05 11:21:00 -06:00
Iñaki Villar c8a326d857 Authenticate CI to Develocity with workload identity (#1109)
## Changes

Moves the workflows that publish to solutions.develocity.cloud from the
long-lived `DV_SOLUTIONS_ACCESS_KEY` to GitHub OIDC tokens, using
Develocity workload identity.

- **`ci-check-and-unit-test.yml` and `ci-update-dist.yml`**: the
Develocity npm agent reads `DEVELOCITY_ACCESS_KEY` directly, and an OIDC
token can't be used there. A pre-step mints the OIDC token and exchanges
it at `/api/auth/token?expiresInHours=2`, the call setup-gradle makes,
for a short-lived Develocity access token. The npm steps read it from
`steps.develocity-oidc.outputs.token-access-key`.
- **`demo-job-summary.yml`** (`develocity-access-key-set` job): a
pre-step mints the OIDC token and passes it to `setup-gradle` as
`develocity-access-key` in `host=token` form. setup-gradle exchanges it,
the same as it does with an access key.

Each job gets `id-token: write`. Pull requests from forks get no OIDC
token, just as they get no secrets today: the step warns and exits
cleanly, and the builds run unauthenticated.

## Not in this PR

`suite-integ-test-other.yml` still passes `DV_SOLUTIONS_ACCESS_KEY` to
`integ-test-inject-develocity.yml`. Those jobs test setup-gradle's own
access-key handling: swapping a classic access key for a short-lived
token, the `GRADLE_ENTERPRISE_ACCESS_KEY` variant, and not leaking the
key when the exchange fails. Feeding them an OIDC token would still run
the exchange, but would stop covering the classic access-key path.
Should they keep a long-lived key on purpose?

## Verification

- [x] CI-check-and-unit-test on this PR ([run
41095618008](https://github.com/gradle/actions/actions/runs/41095618008)):
green, the OIDC token is exchanged, and the npm agent published Build
Scans to solutions.develocity.cloud, for example
[ejvi6m5cprrhg](https://solutions.develocity.cloud/s/ejvi6m5cprrhg) and
[goncdygtosovo](https://solutions.develocity.cloud/s/goncdygtosovo)
- [x] Demo Job Summary dispatched on this branch ([run
41095628373](https://github.com/gradle/actions/actions/runs/41095628373)),
`develocity-access-key-set` job: green, setup-gradle logs `Requesting
short-lived Develocity access token for solutions.develocity.cloud` with
no warning. The sample project publishes to scans.gradle.com, as before.
- [ ] CI-update-dist runs only on `main`/release branches and commits
`dist`, so it is verified after merge
2026-10-30 11:08:40 -07:00
Inaki Villar 8e84bbf095 Authenticate CI to Develocity with workload identity
The npm builds and the demo job summary used the long-lived DV_SOLUTIONS_ACCESS_KEY.
They now mint a GitHub OIDC token for solutions.develocity.cloud. The npm agent reads
DEVELOCITY_ACCESS_KEY directly, so for it the token is exchanged for a short-lived
Develocity access token first.

Signed-off-by: Inaki Villar <[email protected]>
2026-10-30 10:04:20 -07:00
27 changed files with 627 additions and 55 deletions

No files matched your search

@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=21bd5da2de49b642904077f38c0efdc7778e92b3ed0889392dca61b97e389607
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
distributionSha256Sum=d8a18a7a841dd5df825d35a685fad6f2d7f12ac0c280e57b67c27b4a520ba228
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=21bd5da2de49b642904077f38c0efdc7778e92b3ed0889392dca61b97e389607
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
distributionSha256Sum=0b00b0ffe07c4d4789c12d4935a44a7057d55774b7540bd4a3f76f336deb177a
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.0-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=21bd5da2de49b642904077f38c0efdc7778e92b3ed0889392dca61b97e389607
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
distributionSha256Sum=d8a18a7a841dd5df825d35a685fad6f2d7f12ac0c280e57b67c27b4a520ba228
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=21bd5da2de49b642904077f38c0efdc7778e92b3ed0889392dca61b97e389607
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
distributionSha256Sum=d8a18a7a841dd5df825d35a685fad6f2d7f12ac0c280e57b67c27b4a520ba228
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
+24 -3
View File
@@ -14,6 +14,9 @@ permissions:
jobs:
check-format-and-unit-test:
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
@@ -36,13 +39,31 @@ jobs:
run: |
npm exec -y -- pacote extract @gradle-tech/[email protected] ~/.node_libraries/@gradle-tech/develocity-agent
- name: Get GitHub OIDC token for Develocity
id: develocity-oidc
shell: bash
run: |
if [ -z "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
echo "::warning::No GitHub OIDC token available (e.g. PR from a fork), Develocity will not be authenticated"
exit 0
fi
token=$(curl -sSfG -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--data-urlencode "audience=https://solutions.develocity.cloud" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value)
echo "::add-mask::$token"
# Exchange the OIDC token for a short-lived Develocity access token, for the Develocity npm agent that reads DEVELOCITY_ACCESS_KEY directly
access_token=$(curl -sSf --retry 3 -X POST -H "Authorization: Bearer $token" \
"https://solutions.develocity.cloud/api/auth/token?expiresInHours=2")
echo "::add-mask::$access_token"
echo "token-access-key=solutions.develocity.cloud=$access_token" >> "$GITHUB_OUTPUT"
- name: Install npm dependencies
run: |
npm clean-install
working-directory: sources
env:
NODE_OPTIONS: '-r @gradle-tech/develocity-agent/preload'
DEVELOCITY_ACCESS_KEY: '${{ secrets.DV_SOLUTIONS_ACCESS_KEY }}'
DEVELOCITY_ACCESS_KEY: '${{ steps.develocity-oidc.outputs.token-access-key }}'
- name: Check formatting and compile
run: |
@@ -51,7 +72,7 @@ jobs:
working-directory: sources
env:
NODE_OPTIONS: '-r @gradle-tech/develocity-agent/preload'
DEVELOCITY_ACCESS_KEY: '${{ secrets.DV_SOLUTIONS_ACCESS_KEY }}'
DEVELOCITY_ACCESS_KEY: '${{ steps.develocity-oidc.outputs.token-access-key }}'
- name: Run unit tests
run: |
@@ -59,4 +80,4 @@ jobs:
working-directory: sources
env:
NODE_OPTIONS: '-r @gradle-tech/develocity-agent/preload'
DEVELOCITY_ACCESS_KEY: '${{ secrets.DV_SOLUTIONS_ACCESS_KEY }}'
DEVELOCITY_ACCESS_KEY: '${{ steps.develocity-oidc.outputs.token-access-key }}'
+1
View File
@@ -37,6 +37,7 @@ jobs:
permissions:
contents: write
actions: read
id-token: write
needs: caching-integ-tests
uses: ./.github/workflows/suite-integ-test-other.yml
concurrency:
+1
View File
@@ -48,6 +48,7 @@ jobs:
permissions:
contents: write
actions: read
id-token: write
needs: caching-integ-tests
uses: ./.github/workflows/suite-integ-test-other.yml
concurrency:
+21 -2
View File
@@ -20,6 +20,7 @@ jobs:
if: github.repository == 'gradle/actions'
permissions:
contents: write
id-token: write
runs-on: ubuntu-latest
steps:
@@ -38,13 +39,31 @@ jobs:
run: |
npm exec -y -- pacote extract @gradle-tech/[email protected] ~/.node_libraries/@gradle-tech/develocity-agent
- name: Get GitHub OIDC token for Develocity
id: develocity-oidc
shell: bash
run: |
if [ -z "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
echo "::warning::No GitHub OIDC token available (e.g. PR from a fork), Develocity will not be authenticated"
exit 0
fi
token=$(curl -sSfG -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--data-urlencode "audience=https://solutions.develocity.cloud" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value)
echo "::add-mask::$token"
# Exchange the OIDC token for a short-lived Develocity access token, for the Develocity npm agent that reads DEVELOCITY_ACCESS_KEY directly
access_token=$(curl -sSf --retry 3 -X POST -H "Authorization: Bearer $token" \
"https://solutions.develocity.cloud/api/auth/token?expiresInHours=2")
echo "::add-mask::$access_token"
echo "token-access-key=solutions.develocity.cloud=$access_token" >> "$GITHUB_OUTPUT"
- name: Install npm dependencies
run: |
npm clean-install
working-directory: sources
env:
NODE_OPTIONS: '-r @gradle-tech/develocity-agent/preload'
DEVELOCITY_ACCESS_KEY: '${{ secrets.DV_SOLUTIONS_ACCESS_KEY }}'
DEVELOCITY_ACCESS_KEY: '${{ steps.develocity-oidc.outputs.token-access-key }}'
- name: Build distribution
run: |
@@ -54,7 +73,7 @@ jobs:
env:
NODE_OPTIONS: '-r @gradle-tech/develocity-agent/preload'
DEVELOCITY_URL: 'https://solutions.develocity.cloud'
DEVELOCITY_ACCESS_KEY: '${{ secrets.DV_SOLUTIONS_ACCESS_KEY }}'
DEVELOCITY_ACCESS_KEY: '${{ steps.develocity-oidc.outputs.token-access-key }}'
- name: Copy the generated sources/dist directory to the top-level dist
run: |
+18 -1
View File
@@ -259,6 +259,9 @@ jobs:
develocity-access-key-set:
needs: build-distribution
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout sources
@@ -266,10 +269,24 @@ jobs:
- name: Initialize integ-test
uses: ./.github/actions/init-integ-test
- name: Get GitHub OIDC token for Develocity
id: develocity-oidc
shell: bash
run: |
if [ -z "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
echo "::warning::No GitHub OIDC token available (e.g. PR from a fork), Develocity will not be authenticated"
exit 0
fi
token=$(curl -sSfG -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--data-urlencode "audience=https://solutions.develocity.cloud" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value)
echo "::add-mask::$token"
echo "access-key=solutions.develocity.cloud=$token" >> "$GITHUB_OUTPUT"
- name: Setup Gradle
uses: ./setup-gradle
with:
develocity-access-key: ${{ secrets.DV_SOLUTIONS_ACCESS_KEY }}
develocity-access-key: ${{ steps.develocity-oidc.outputs.access-key }}
- name: Build kotlin-dsl project
working-directory: .github/workflow-samples/kotlin-dsl
run: ./gradlew assemble
@@ -46,7 +46,6 @@ jobs:
shell: bash
working-directory: .github/workflow-samples/groovy-dsl
run: |
grep -q 'Eclipse Temurin JDK 8' output.txt || (echo "::error::Did not detect preinstalled JDK 8" && exit 1)
grep -q 'Eclipse Temurin JDK 11' output.txt || (echo "::error::Did not detect preinstalled JDK 11" && exit 1)
grep -q 'Eclipse Temurin JDK 17' output.txt || (echo "::error::Did not detect preinstalled JDK 17" && exit 1)
grep -q 'Eclipse Temurin JDK 21' output.txt || (echo "::error::Did not detect preinstalled JDK 21" && exit 1)
@@ -96,7 +95,6 @@ jobs:
shell: bash
working-directory: .github/workflow-samples/groovy-dsl
run: |
grep -q 'Eclipse Temurin JDK 8' output.txt || (echo "::error::Did not detect preinstalled JDK 8" && exit 1)
grep -q 'Eclipse Temurin JDK 11' output.txt || (echo "::error::Did not detect preinstalled JDK 11" && exit 1)
grep -q 'Eclipse Temurin JDK 17' output.txt || (echo "::error::Did not detect preinstalled JDK 17" && exit 1)
grep -q 'Eclipse Temurin JDK 21' output.txt || (echo "::error::Did not detect preinstalled JDK 21" && exit 1)
@@ -12,9 +12,6 @@ on:
skip-dist:
type: boolean
default: false
secrets:
DEVELOCITY_ACCESS_KEY:
required: true
env:
SKIP_DIST: ${{ inputs.skip-dist }}
@@ -46,12 +43,14 @@ jobs:
- plugin-version: '4.6.1'
accessKeyEnv: DEVELOCITY_ACCESS_KEY
runs-on: ${{ matrix.os }}
permissions:
contents: read
id-token: write
env:
DEVELOCITY_INJECTION_ENABLED: true
DEVELOCITY_INJECTION_URL: https://solutions.develocity.cloud
DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION: '2.2.1'
${{matrix.accessKeyEnv}}: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
steps:
- name: Checkout sources
@@ -60,6 +59,19 @@ jobs:
uses: ./.github/actions/init-integ-test
with:
java-version: ${{ matrix.java-version }}
- name: Get GitHub OIDC token for Develocity
id: develocity-oidc
shell: bash
run: |
if [ -z "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
echo "::warning::No GitHub OIDC token available (e.g. PR from a fork), Develocity will not be authenticated"
exit 0
fi
token=$(curl -sSfG -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--data-urlencode "audience=https://solutions.develocity.cloud" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value)
echo "::add-mask::$token"
echo "${{ matrix.accessKeyEnv }}=solutions.develocity.cloud=$token" >> "$GITHUB_ENV"
- name: Setup Gradle
id: setup-gradle
uses: ./setup-gradle
@@ -104,6 +116,9 @@ jobs:
- gradle: '5.6.4'
java-version: 11
runs-on: ${{ matrix.os }}
permissions:
contents: read
id-token: write
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -111,13 +126,26 @@ jobs:
uses: ./.github/actions/init-integ-test
with:
java-version: ${{ matrix.java-version }}
- name: Get GitHub OIDC token for Develocity
id: develocity-oidc
shell: bash
run: |
if [ -z "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
echo "::warning::No GitHub OIDC token available (e.g. PR from a fork), Develocity will not be authenticated"
exit 0
fi
token=$(curl -sSfG -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--data-urlencode "audience=https://solutions.develocity.cloud" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value)
echo "::add-mask::$token"
echo "access-key=solutions.develocity.cloud=$token" >> "$GITHUB_OUTPUT"
- name: Setup Gradle
id: setup-gradle
uses: ./setup-gradle
with:
cache-read-only: false # For testing, allow writing cache entries on non-default branches
gradle-version: ${{ matrix.gradle }}
develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
develocity-access-key: ${{ steps.develocity-oidc.outputs.access-key }}
develocity-token-expiry: 1
- name: Run Gradle build
id: gradle
@@ -140,9 +168,6 @@ jobs:
DEVELOCITY_INJECTION_URL: 'https://localhost:3333/'
DEVELOCITY_INJECTION_DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION: '2.1'
# Access key also set as an env var, we want to check it does not leak
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
strategy:
fail-fast: false
matrix:
@@ -160,6 +185,9 @@ jobs:
- gradle: '5.6.4'
java-version: 11
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout sources
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -167,13 +195,29 @@ jobs:
uses: ./.github/actions/init-integ-test
with:
java-version: ${{ matrix.java-version }}
# Access key also set as an env var, we want to check it does not leak
- name: Get GitHub OIDC token for Develocity
id: develocity-oidc
shell: bash
run: |
if [ -z "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
echo "::warning::No GitHub OIDC token available (e.g. PR from a fork), Develocity will not be authenticated"
exit 0
fi
token=$(curl -sSfG -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--data-urlencode "audience=https://solutions.develocity.cloud" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value)
echo "::add-mask::$token"
echo "access-key=solutions.develocity.cloud=$token" >> "$GITHUB_OUTPUT"
echo "GRADLE_ENTERPRISE_ACCESS_KEY=solutions.develocity.cloud=$token" >> "$GITHUB_ENV"
echo "DEVELOCITY_ACCESS_KEY=solutions.develocity.cloud=$token" >> "$GITHUB_ENV"
- name: Setup Gradle
id: setup-gradle
uses: ./setup-gradle
with:
gradle-version: ${{ matrix.gradle }}
cache-read-only: false # For testing, allow writing cache entries on non-default branches
develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
develocity-access-key: ${{ steps.develocity-oidc.outputs.access-key }}
- name: Run Gradle build
id: gradle
working-directory: .github/workflow-samples/no-ge
@@ -184,8 +228,9 @@ jobs:
run: "[ \"${GRADLE_ENTERPRISE_ACCESS_KEY}\" != \"\" ] || (echo 'GRADLE_ENTERPRISE_ACCESS_KEY is still supported in v3!'; exit 1)"
inject-develocity-with-access-key-from-input-actions:
env:
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
permissions:
contents: read
id-token: write
strategy:
fail-fast: false
matrix:
@@ -210,6 +255,19 @@ jobs:
uses: ./.github/actions/init-integ-test
with:
java-version: ${{ matrix.java-version }}
- name: Get GitHub OIDC token for Develocity
id: develocity-oidc
shell: bash
run: |
if [ -z "$ACTIONS_ID_TOKEN_REQUEST_URL" ]; then
echo "::warning::No GitHub OIDC token available (e.g. PR from a fork), Develocity will not be authenticated"
exit 0
fi
token=$(curl -sSfG -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
--data-urlencode "audience=https://solutions.develocity.cloud" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r .value)
echo "::add-mask::$token"
echo "DEVELOCITY_ACCESS_KEY=solutions.develocity.cloud=$token" >> "$GITHUB_ENV"
- name: Setup Gradle
id: setup-gradle
uses: ./setup-gradle
+3 -2
View File
@@ -22,11 +22,12 @@ jobs:
develocity-injection:
if: ${{ ! github.event.pull_request.head.repo.fork }}
permissions:
contents: read
id-token: write
uses: ./.github/workflows/integ-test-inject-develocity.yml
with:
skip-dist: ${{ inputs.skip-dist }}
secrets:
DEVELOCITY_ACCESS_KEY: ${{ secrets.DV_SOLUTIONS_ACCESS_KEY }}
gradle-support-status:
permissions:
+80 -13
View File
@@ -431,6 +431,8 @@ As well as reducing the content that needs to be saved to the GitHub Actions cac
this setup will ensure that your CI builds populate the remote cache and keep the cache entries fresh by reading these entries.
Local builds can then benefit from the remote cache.
If your build uses Develocity, `setup-gradle` can apply this setup for you with [Develocity injection](#configuring-the-build-cache-with-develocity-injection).
## Basic Caching
Basic Caching is an open-source (MIT) alternative that uses `@actions/cache` to provide straightforward, path-based caching of Gradle dependencies. It uses the same caching strategy as `actions/setup-java` with `cache: gradle`.
@@ -979,20 +981,20 @@ This access key will be used during the action execution to get a short-lived to
### Configuring Develocity injection
The `init-script` supports several additional configuration parameters that you may find useful. All configuration options (required and optional) are detailed below:
The `init-script` supports several additional configuration parameters that you may find useful. These configuration options (required and optional) are detailed below:
| Variable | Required | Description |
|--------------------------------------| :---: |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| develocity-injection-enabled | :white_check_mark: | enables Develocity injection |
| develocity-url | :white_check_mark: | the URL of the Develocity server |
| develocity-allow-untrusted-server | | allow communication with an untrusted server; set to _true_ if your Develocity instance is using a self-signed certificate |
| develocity-capture-file-fingerprints | | enables capturing the paths and content hashes of each individual input file |
| develocity-enforce-url | | enforce the configured Develocity URL over a URL configured in the project's build; set to _true_ to enforce publication of build scans to the configured Develocity URL |
| develocity-plugin-version | :white_check_mark: | the version of the [Develocity Gradle plugin](https://docs.gradle.com/develocity/gradle-plugin/) to apply |
| develocity-ccud-plugin-version | | the version of the [Common Custom User Data Gradle plugin](https://github.com/gradle/common-custom-user-data-gradle-plugin) to apply, if any |
| gradle-plugin-repository-url | | the URL of the repository to use when resolving the Develocity and CCUD plugins; the Gradle Plugin Portal is used by default |
| gradle-plugin-repository-username | | the username for the repository URL to use when resolving the Develocity and CCUD plugins |
| gradle-plugin-repository-password | | the password for the repository URL to use when resolving the Develocity and CCUD plugins; Consider using secrets to pass the value to this variable |
| Variable | Required | Description |
|--------------------------------------| :---: |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| develocity-injection-enabled | :white_check_mark: | enables Develocity injection |
| develocity-url | :white_check_mark: | the URL of the Develocity server |
| develocity-allow-untrusted-server | | allow communication with an untrusted server; set to _true_ if your Develocity instance is using a self-signed certificate |
| develocity-capture-file-fingerprints | | enables capturing the paths and content hashes of each individual input file |
| develocity-enforce-url | | enforce the configured Develocity URL over a URL configured in the project's build; set to _true_ to enforce publication of build scans to the configured Develocity URL; a Develocity Build Cache connector without a server defined follows the enforced URL, but a server explicitly configured in the project's build is not changed |
| develocity-plugin-version | :white_check_mark: | the version of the [Develocity Gradle plugin](https://docs.gradle.com/develocity/gradle-plugin/) to apply |
| develocity-ccud-plugin-version | | the version of the [Common Custom User Data Gradle plugin](https://github.com/gradle/common-custom-user-data-gradle-plugin) to apply, if any |
| gradle-plugin-repository-url | | the URL of the repository to use when resolving the Develocity and CCUD plugins; the Gradle Plugin Portal is used by default |
| gradle-plugin-repository-username | | the username for the repository URL to use when resolving the Develocity and CCUD plugins |
| gradle-plugin-repository-password | | the password for the repository URL to use when resolving the Develocity and CCUD plugins; Consider using secrets to pass the value to this variable |
The input parameters can be expressed as environment variables following the relationships outlined in the table below:
@@ -1026,6 +1028,71 @@ Here's an example using the env vars:
DEVELOCITY_INJECTION_CCUD_PLUGIN_VERSION: '2.2.1'
```
### Configuring the build cache with Develocity injection
> [!IMPORTANT]
> Develocity injection can configure the local and remote build caches, but it cannot enable
> the [Gradle build cache](https://docs.gradle.org/current/userguide/build_cache.html) feature
> itself. Enable it with `org.gradle.caching=true` in `gradle.properties` or with the
> `--build-cache` command line option. Without it, the `setup-gradle` build cache configuration
> has no effect.
Develocity injection can also configure the build cache of your build.
The remote build cache is configured with the [Develocity Build Cache connector](https://docs.gradle.com/develocity/gradle-plugin/current/#using_build_caching), which uses the Develocity server unless another server is configured.
The connector authenticates with the same access key the Develocity Gradle plugin uses to publish Build Scans.
| Input | Description |
|-------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| develocity-enforce-build-cache | set to _true_ to replace a remote build cache configured in the project's build with the Develocity Build Cache connector |
| develocity-remote-build-cache-enabled | enable the remote build cache |
| develocity-remote-build-cache-push | store task outputs in the remote build cache |
| develocity-remote-build-cache-server | the URL of the remote build cache server; the Develocity server is used by default |
| develocity-remote-build-cache-path | the path of the remote build cache on the server |
| develocity-remote-build-cache-allow-insecure-protocol | allow communication with the remote build cache over plain HTTP |
| develocity-remote-build-cache-allow-untrusted-server | allow communication with an untrusted remote build cache server |
| develocity-local-build-cache-enabled | enable the local build cache |
| develocity-local-build-cache-push | store task outputs in the local build cache |
The input parameters can be expressed as environment variables following the relationships outlined in the table below:
| Input | Environment Variable |
|-------------------------------------------------------|-----------------------------------------------------------------|
| develocity-enforce-build-cache | DEVELOCITY_INJECTION_ENFORCE_BUILD_CACHE |
| develocity-remote-build-cache-enabled | DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_ENABLED |
| develocity-remote-build-cache-push | DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_PUSH |
| develocity-remote-build-cache-server | DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_SERVER |
| develocity-remote-build-cache-path | DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_PATH |
| develocity-remote-build-cache-allow-insecure-protocol | DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_ALLOW_INSECURE_PROTOCOL |
| develocity-remote-build-cache-allow-untrusted-server | DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_ALLOW_UNTRUSTED_SERVER |
| develocity-local-build-cache-enabled | DEVELOCITY_INJECTION_LOCAL_BUILD_CACHE_ENABLED |
| develocity-local-build-cache-push | DEVELOCITY_INJECTION_LOCAL_BUILD_CACHE_PUSH |
The remote build cache is only configured when `develocity-remote-build-cache-enabled` is set, and the local build cache only when `develocity-local-build-cache-enabled` is set.
If the project's build already configures a remote build cache, the existing build cache configuration is not modified unless `develocity-enforce-build-cache` is set to _true_.
If the remote build cache cannot be configured, the local build cache is not configured either, so a build is never left with a partial build cache configuration.
Build cache configuration requires Gradle 6.0 or later and the Develocity Gradle plugin 3.11 or later.
With the configuration cache enabled, it requires Gradle 7.5.1 or later.
Builds that do not meet these requirements keep their own build cache configuration.
Here's an example that has CI builds populate the remote build cache on the Develocity server and disables the local build cache:
```yaml
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6
with:
develocity-access-key: ${{ secrets.MY_DEVELOCITY_ACCESS_KEY }}
develocity-injection-enabled: true
develocity-url: 'https://develocity.your-server.com'
develocity-plugin-version: '4.0'
develocity-remote-build-cache-enabled: true
develocity-remote-build-cache-push: true
develocity-local-build-cache-enabled: false
- name: Run a Gradle build with the Develocity remote build cache
run: ./gradlew build --build-cache
```
# Dependency verification
Develocity injection, Build Scan publishing and Dependency Graph generation all work by applying external plugins to your build.
+27
View File
@@ -136,6 +136,33 @@ inputs:
develocity-ccud-plugin-version:
type: string
develocity-enforce-build-cache:
type: boolean
develocity-remote-build-cache-enabled:
type: boolean
develocity-remote-build-cache-push:
type: boolean
develocity-remote-build-cache-server:
type: string
develocity-remote-build-cache-path:
type: string
develocity-remote-build-cache-allow-insecure-protocol:
type: boolean
develocity-remote-build-cache-allow-untrusted-server:
type: boolean
develocity-local-build-cache-enabled:
type: boolean
develocity-local-build-cache-push:
type: boolean
gradle-plugin-repository-url:
type: string
+37 -1
View File
@@ -174,7 +174,7 @@ inputs:
required: false
develocity-enforce-url:
description: Enforce the configured Develocity URL over a URL configured in the project's build; set to _true_ to enforce publication of build scans to the configured Develocity URL.
description: Enforce the configured Develocity URL over a URL configured in the project's build; set to _true_ to enforce publication of build scans to the configured Develocity URL; a Develocity Build Cache connector without a server defined follows the enforced URL, but a server explicitly configured in the project's build is not changed.
required: false
develocity-plugin-version:
@@ -185,6 +185,42 @@ inputs:
description: The version of the Common Custom User Data Gradle plugin to apply, if any.
required: false
develocity-enforce-build-cache:
description: Replace a remote build cache configured in the project's build with the Develocity Build Cache connector.
required: false
develocity-remote-build-cache-enabled:
description: Enables the remote build cache.
required: false
develocity-remote-build-cache-push:
description: Store task outputs in the remote build cache.
required: false
develocity-remote-build-cache-server:
description: The URL of the remote build cache server; the Develocity server is used by default.
required: false
develocity-remote-build-cache-path:
description: The path of the remote build cache on the server.
required: false
develocity-remote-build-cache-allow-insecure-protocol:
description: Allow communication with the remote build cache over plain HTTP.
required: false
develocity-remote-build-cache-allow-untrusted-server:
description: Allow communication with an untrusted remote build cache server.
required: false
develocity-local-build-cache-enabled:
description: Enables the local build cache.
required: false
develocity-local-build-cache-push:
description: Store task outputs in the local build cache.
required: false
gradle-plugin-repository-url:
description: The URL of the repository to use when resolving the Develocity and CCUD plugins; the Gradle Plugin Portal is used by default.
required: false
+36
View File
@@ -312,6 +312,42 @@ export class DevelocityConfig {
return core.getInput('develocity-ccud-plugin-version')
}
getDevelocityEnforceBuildCache(): boolean | undefined {
return getOptionalBooleanInput('develocity-enforce-build-cache')
}
getDevelocityRemoteBuildCacheEnabled(): boolean | undefined {
return getOptionalBooleanInput('develocity-remote-build-cache-enabled')
}
getDevelocityRemoteBuildCachePush(): boolean | undefined {
return getOptionalBooleanInput('develocity-remote-build-cache-push')
}
getDevelocityRemoteBuildCacheServer(): string {
return core.getInput('develocity-remote-build-cache-server')
}
getDevelocityRemoteBuildCachePath(): string {
return core.getInput('develocity-remote-build-cache-path')
}
getDevelocityRemoteBuildCacheAllowInsecureProtocol(): boolean | undefined {
return getOptionalBooleanInput('develocity-remote-build-cache-allow-insecure-protocol')
}
getDevelocityRemoteBuildCacheAllowUntrustedServer(): boolean | undefined {
return getOptionalBooleanInput('develocity-remote-build-cache-allow-untrusted-server')
}
getDevelocityLocalBuildCacheEnabled(): boolean | undefined {
return getOptionalBooleanInput('develocity-local-build-cache-enabled')
}
getDevelocityLocalBuildCachePush(): boolean | undefined {
return getOptionalBooleanInput('develocity-local-build-cache-push')
}
getPluginRepository(): PluginRepositoryConfig {
return new PluginRepositoryConfig()
}
+33
View File
@@ -27,6 +27,39 @@ export function setup(config: DevelocityConfig): void {
'DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_PASSWORD',
config.getPluginRepository().getPassword()
)
maybeExportVariableNotEmpty('DEVELOCITY_INJECTION_ENFORCE_BUILD_CACHE', config.getDevelocityEnforceBuildCache())
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_ENABLED',
config.getDevelocityRemoteBuildCacheEnabled()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_PUSH',
config.getDevelocityRemoteBuildCachePush()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_SERVER',
config.getDevelocityRemoteBuildCacheServer()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_PATH',
config.getDevelocityRemoteBuildCachePath()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_ALLOW_INSECURE_PROTOCOL',
config.getDevelocityRemoteBuildCacheAllowInsecureProtocol()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_ALLOW_UNTRUSTED_SERVER',
config.getDevelocityRemoteBuildCacheAllowUntrustedServer()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_LOCAL_BUILD_CACHE_ENABLED',
config.getDevelocityLocalBuildCacheEnabled()
)
maybeExportVariableNotEmpty(
'DEVELOCITY_INJECTION_LOCAL_BUILD_CACHE_PUSH',
config.getDevelocityLocalBuildCachePush()
)
// If build-scan-publish is enabled, ensure the environment variables are set
// The DEVELOCITY_PLUGIN_VERSION and DEVELOCITY_CCUD_PLUGIN_VERSION are set to the latest versions
@@ -1,6 +1,6 @@
/*
* Initscript for injection of Develocity into Gradle builds.
* Version: 2.0.1
* Version: 2.1
*/
import org.gradle.util.GradleVersion
@@ -94,6 +94,11 @@ static getInputParam(Gradle gradle, String name) {
return System.getProperty(name) ?: gradle.startParameter.systemPropertiesArgs[name] ?: System.getenv(envVarName)
}
static Boolean getBooleanInputParam(Gradle gradle, String name, Boolean defaultValue = null) {
def value = getInputParam(gradle, name)
return value ? Boolean.parseBoolean(value) : defaultValue
}
def isTopLevelBuild = !gradle.parent
if (!isTopLevelBuild) {
return
@@ -102,7 +107,7 @@ if (!isTopLevelBuild) {
def requestedInitScriptName = getInputParam(gradle, 'develocity-injection.init-script-name')
def initScriptName = buildscript.sourceFile.name
def develocityInjectionEnabled = Boolean.parseBoolean(getInputParam(gradle, "develocity-injection.enabled"))
def develocityInjectionEnabled = getBooleanInputParam(gradle, "develocity-injection.enabled", false)
if (develocityInjectionEnabled) {
if (requestedInitScriptName != initScriptName) {
logger.log(LogLevel.WARN, "Develocity injection not enabled because requested init script name was '${requestedInitScriptName}', but '${initScriptName}' was expected")
@@ -136,16 +141,26 @@ void enableDevelocityInjection() {
def CCUD_PLUGIN_CLASS = 'com.gradle.CommonCustomUserDataGradlePlugin'
def develocityUrl = getInputParam(gradle, 'develocity-injection.url')
def develocityAllowUntrustedServer = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.allow-untrusted-server'))
def develocityEnforceUrl = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.enforce-url'))
def buildScanUploadInBackground = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.upload-in-background'))
def develocityCaptureFileFingerprints = getInputParam(gradle, 'develocity-injection.capture-file-fingerprints') ? Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.capture-file-fingerprints')) : true
def develocityAllowUntrustedServer = getBooleanInputParam(gradle, 'develocity-injection.allow-untrusted-server', false)
def develocityEnforceUrl = getBooleanInputParam(gradle, 'develocity-injection.enforce-url', false)
def buildScanUploadInBackground = getBooleanInputParam(gradle, 'develocity-injection.upload-in-background', false)
def develocityCaptureFileFingerprints = getBooleanInputParam(gradle, 'develocity-injection.capture-file-fingerprints', true)
def develocityPluginVersion = getInputParam(gradle, 'develocity-injection.develocity-plugin.version')
def ccudPluginVersion = getInputParam(gradle, 'develocity-injection.ccud-plugin.version')
def buildScanTermsOfUseUrl = getInputParam(gradle, 'develocity-injection.terms-of-use.url')
def buildScanTermsOfUseAgree = getInputParam(gradle, 'develocity-injection.terms-of-use.agree')
def ciAutoInjectionCustomValueValue = getInputParam(gradle, 'develocity-injection.custom-value')
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def logLevel = getBooleanInputParam(gradle, 'develocity-injection.debug', false) ? LogLevel.LIFECYCLE : LogLevel.INFO
def enforceBuildCache = getBooleanInputParam(gradle, 'develocity-injection.enforce-build-cache', false)
def remoteBuildCacheEnabled = getBooleanInputParam(gradle, 'develocity-injection.remote-build-cache.enabled')
def remoteBuildCachePush = getBooleanInputParam(gradle, 'develocity-injection.remote-build-cache.push')
def remoteBuildCacheServer = getInputParam(gradle, 'develocity-injection.remote-build-cache.server')
def remoteBuildCachePath = getInputParam(gradle, 'develocity-injection.remote-build-cache.path')
def remoteBuildCacheAllowInsecureProtocol = getBooleanInputParam(gradle, 'develocity-injection.remote-build-cache.allow-insecure-protocol')
def remoteBuildCacheAllowUntrustedServer = getBooleanInputParam(gradle, 'develocity-injection.remote-build-cache.allow-untrusted-server')
def localBuildCacheEnabled = getBooleanInputParam(gradle, 'develocity-injection.local-build-cache.enabled')
def localBuildCachePush = getBooleanInputParam(gradle, 'develocity-injection.local-build-cache.push')
def atLeastGradle5 = GradleVersion.current() >= GradleVersion.version('5.0')
def atLeastGradle4 = GradleVersion.current() >= GradleVersion.version('4.0')
@@ -158,6 +173,10 @@ void enableDevelocityInjection() {
return geValue instanceof Closure<?> ? geValue() : geValue
}
def isDevelocityPluginMissing = { Settings settings ->
!settings.pluginManager.hasPlugin(GRADLE_ENTERPRISE_PLUGIN_ID) && !settings.pluginManager.hasPlugin(DEVELOCITY_PLUGIN_ID)
}
def printEnforcingDevelocityUrl = {
logger.log(logLevel, "Enforcing Develocity: $develocityUrl, allowUntrustedServer: $develocityAllowUntrustedServer")
}
@@ -166,6 +185,92 @@ void enableDevelocityInjection() {
logger.log(logLevel, "Accepting Gradle Terms of Use: $buildScanTermsOfUseUrl")
}
def printBuildCacheSkipReason = { String reason, boolean isMisconfiguration = false ->
def level = isMisconfiguration ? LogLevel.WARN : logLevel
if (remoteBuildCacheEnabled != null) {
logger.log(level, "Remote build cache not configured because $reason")
if (localBuildCacheEnabled != null) {
logger.log(level, "Local build cache not configured to avoid leaving the build cache partially configured")
}
} else if (localBuildCacheEnabled != null) {
logger.log(level, "Local build cache not configured because $reason")
}
}
def configureLocalBuildCache = { Settings settings ->
settings.buildCache.local { local ->
local.enabled = localBuildCacheEnabled
if (localBuildCachePush != null) {
local.push = localBuildCachePush
}
logger.log(logLevel, "Configuring the local build cache: enabled: ${local.enabled}, push: ${local.push}")
}
}
def configureRemoteBuildCache = { Settings settings, Class connectorType ->
settings.buildCache.remote(connectorType) { remote ->
remote.enabled = remoteBuildCacheEnabled
if (remoteBuildCachePush != null) {
remote.push = remoteBuildCachePush
}
if (remoteBuildCacheServer) {
remote.server = remoteBuildCacheServer
}
if (remoteBuildCachePath) {
remote.path = remoteBuildCachePath
}
if (remoteBuildCacheAllowInsecureProtocol != null) {
remote.allowInsecureProtocol = remoteBuildCacheAllowInsecureProtocol
}
if (remoteBuildCacheAllowUntrustedServer != null) {
remote.allowUntrustedServer = remoteBuildCacheAllowUntrustedServer
}
logger.log(logLevel, "Configuring the remote build cache: ${remote.server ?: 'Develocity server'}, path: ${remote.path ?: '<default>'}, enabled: ${remote.enabled}, push: ${remote.push}, allowInsecureProtocol: ${remote.allowInsecureProtocol}, allowUntrustedServer: ${remote.allowUntrustedServer == null ? '<default>' : remote.allowUntrustedServer}")
}
}
def configureBuildCache = { Settings settings ->
// The configuration cache was first introduced in Gradle 6.6, and before 7.5.1 a build fails when it reuses an entry that uses the Develocity Build Cache connector
if (GradleVersion.current() >= GradleVersion.version('6.6') && GradleVersion.current() < GradleVersion.version('7.5.1') && gradle.startParameter.isConfigurationCache()) {
printBuildCacheSkipReason("build cache configuration via injection requires Gradle 7.5.1 or later when using the configuration cache")
return
}
if (isDevelocityPluginMissing(settings)) {
printBuildCacheSkipReason("the Develocity Gradle plugin is not applied")
return
}
def develocityExtension = getDevelocitySettingsExtension(settings)
if (!develocityExtension.metaClass.respondsTo(develocityExtension, 'getBuildCache')) {
printBuildCacheSkipReason("this version of the Develocity Gradle plugin does not support the Develocity Build Cache connector", develocityPluginVersion && isNotAtLeast(develocityPluginVersion, '3.11'))
return
}
def existingRemoteBuildCache = settings.buildCache.remote
if (existingRemoteBuildCache != null && !enforceBuildCache) {
printBuildCacheSkipReason("a remote build cache is already configured")
return
}
if (remoteBuildCacheEnabled && !remoteBuildCacheServer && !hasDevelocityServer(develocityExtension)) {
printBuildCacheSkipReason("no Develocity server is configured")
return
}
if (remoteBuildCacheEnabled != null) {
Class develocityBuildCacheConnector = develocityExtension.buildCache
if (existingRemoteBuildCache in develocityBuildCacheConnector) {
resetRemoteBuildCache(settings)
} else if (existingRemoteBuildCache != null) {
logger.log(logLevel, "Replacing the existing remote build cache with the Develocity Build Cache connector")
}
configureRemoteBuildCache(settings, develocityBuildCacheConnector)
}
if (localBuildCacheEnabled != null) {
configureLocalBuildCache(settings)
}
}
// finish early if DV plugin version is unsupported (v3.6.4 is the minimum version tested and supports back to DV 2021.1)
if (develocityPluginVersion && isNotAtLeast(develocityPluginVersion, '3.6.4')) {
logger.log(LogLevel.WARN, "Develocity Gradle plugin must be at least 3.6.4. Configured version is $develocityPluginVersion.")
@@ -281,10 +386,15 @@ void enableDevelocityInjection() {
}
}
}
if (remoteBuildCacheEnabled != null || localBuildCacheEnabled != null) {
// The Develocity Build Cache connector is only available when the Develocity Gradle plugin is applied to settings.
printBuildCacheSkipReason("build cache configuration via injection requires Gradle 6.0 or later")
}
} else {
gradle.settingsEvaluated { settings ->
if (develocityPluginVersion) {
if (!settings.pluginManager.hasPlugin(GRADLE_ENTERPRISE_PLUGIN_ID) && !settings.pluginManager.hasPlugin(DEVELOCITY_PLUGIN_ID)) {
if (isDevelocityPluginMissing(settings)) {
def pluginClass = dvOrGe(DEVELOCITY_PLUGIN_CLASS, GRADLE_ENTERPRISE_PLUGIN_CLASS)
applyPluginExternally(settings.pluginManager, pluginClass, develocityPluginVersion)
if (develocityUrl) {
@@ -375,12 +485,16 @@ void enableDevelocityInjection() {
settings.pluginManager.apply(initscript.classLoader.loadClass(CCUD_PLUGIN_CLASS))
}
}
if (remoteBuildCacheEnabled != null || localBuildCacheEnabled != null) {
configureBuildCache(settings)
}
}
}
}
void applyPluginExternally(def pluginManager, String pluginClassName, String pluginVersion) {
def logLevel = Boolean.parseBoolean(getInputParam(gradle, 'develocity-injection.debug')) ? LogLevel.LIFECYCLE : LogLevel.INFO
def logLevel = getBooleanInputParam(gradle, 'develocity-injection.debug', false) ? LogLevel.LIFECYCLE : LogLevel.INFO
logger.log(logLevel, "Applying $pluginClassName with version $pluginVersion via init script")
def externallyApplied = 'develocity.externally-applied'
@@ -427,10 +541,25 @@ static def eachDevelocitySettingsExtension(def settings, def dvAction, def geAct
}
}
/**
* Return the 'develocity' extension.
* If no 'develocity' extension is found, returns the 'gradleEnterprise' extension.
* In some versions, the Develocity Gradle plugin creates both extensions, and we want to prefer 'develocity'.
*/
static def getDevelocitySettingsExtension(def settings) {
def GRADLE_ENTERPRISE_EXTENSION_CLASS = 'com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension'
def DEVELOCITY_CONFIGURATION_CLASS = 'com.gradle.develocity.agent.gradle.DevelocityConfiguration'
def elements = settings.extensions.extensionsSchema.elements
def element = elements.find { it.publicType.concreteClass.name == DEVELOCITY_CONFIGURATION_CLASS } ?:
elements.find { it.publicType.concreteClass.name == GRADLE_ENTERPRISE_EXTENSION_CLASS }
return element ? settings[element.name] : null
}
/**
* Apply the `dvAction` to the 'develocity' extension.
* If no 'develocity' extension is found, apply the `bsAction` to the 'buildScan' extension.
* (The develocity plugin creates both extensions, and we want to prefer configuring 'develocity').
* In some versions, the Develocity Gradle plugin creates both extensions, and we want to prefer 'develocity'.
*/
static def eachDevelocityProjectExtension(def project, def dvAction, def bsAction = dvAction) {
def BUILD_SCAN_PLUGIN_ID = 'com.gradle.build-scan'
@@ -453,6 +582,24 @@ static def eachDevelocityProjectExtension(def project, def dvAction, def bsActio
}
}
/**
* The type for 'server' is Property in the 'develocity' extension, and String in the 'gradleEnterprise' extension.
*/
static boolean hasDevelocityServer(def develocityExtension) {
def server = develocityExtension.server
// The Provider type cannot be referenced here because the script must still compile on Gradle 3.x
return server && (!server.metaClass.respondsTo(server, 'isPresent') || server.isPresent())
}
/**
* Gradle has no API to reset a remote build cache or to replace it with a new one of the same type.
* A workaround for this is to temporarily switch to a remote build cache of a different type.
* Switching to an HttpBuildCache first makes the next Develocity Build Cache connector start from default values.
*/
static void resetRemoteBuildCache(Settings settings) {
settings.buildCache.remote(HttpBuildCache) {}
}
static boolean isAtLeast(String versionUnderTest, String referenceVersion) {
GradleVersion.version(versionUnderTest) >= GradleVersion.version(referenceVersion)
}
Binary file not shown.
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=21bd5da2de49b642904077f38c0efdc7778e92b3ed0889392dca61b97e389607
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
distributionSha256Sum=d8a18a7a841dd5df825d35a685fad6f2d7f12ac0c280e57b67c27b4a520ba228
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
@@ -1,6 +1,7 @@
plugins {
id "com.gradle.develocity" version "4.6.1"
id "com.gradle.common-custom-user-data-gradle-plugin" version "2.4.0"
id "org.gradle.toolchains.foojay-resolver-convention" version "1.0.0"
}
develocity {
@@ -147,6 +147,16 @@ class BaseInitScriptTest extends Specification {
buildFile.text = maybeAddPluginsToRootProject(gradleVersion, false, CCUD_PLUGIN_VERSION, serverUrl) + buildFile.text
}
def declareHttpBuildCache() {
settingsFile << """
buildCache {
remote(HttpBuildCache) {
url = 'https://build-cache-server.invalid/cache/'
}
}
"""
}
String maybeAddPluginsToSettings(GradleVersion gradleVersion, boolean legacy, String ccudPluginVersion, URI serverUri) {
if (gradleVersion < GradleVersion.version('6.0')) {
'' // applied in build.gradle
@@ -354,6 +354,47 @@ class TestDevelocityInjection extends BaseInitScriptTest {
testGradleVersion << CONFIGURATION_CACHE_VERSIONS
}
def "configures remote and local build cache when Develocity plugin is applied by the init script"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:
def config = testConfig().withRemoteBuildCache().withLocalBuildCache(false)
def result = run(testGradleVersion, config)
then:
outputContainsDevelocityPluginApplicationViaInitScript(result, testGradleVersion.gradleVersion)
outputContainsRemoteBuildCacheConfiguration(result, 'Develocity server', '<default>', true, true)
outputContainsLocalBuildCacheConfiguration(result, false, true)
and:
outputContainsBuildScanUrl(result)
where:
testGradleVersion << SETTINGS_PLUGIN_VERSIONS
}
def "enforces remote build cache in project if enforce build cache parameter is enabled"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
given:
declareHttpBuildCache()
when:
def config = testConfig().withRemoteBuildCache().withRemoteBuildCacheLocation('https://build-cache-server.invalid', 'cache').withEnforceBuildCache()
def result = run(testGradleVersion, config)
then:
outputContainsDevelocityPluginApplicationViaInitScript(result, testGradleVersion.gradleVersion)
outputReplacesRemoteBuildCache(result)
outputContainsRemoteBuildCacheConfiguration(result, 'https://build-cache-server.invalid', 'cache', true, true)
and:
outputContainsBuildScanUrl(result)
where:
testGradleVersion << SETTINGS_PLUGIN_VERSIONS
}
void outputContainsBuildScanUrl(BuildResult result) {
def opt = ['Publishing build scan...', 'Publishing Build Scan...', 'Publishing Build Scan to Develocity...'].stream()
.filter { result.output.contains("${it}\n${mockScansServer.address}s/$PUBLIC_BUILD_SCAN_ID") }.findFirst()
@@ -441,6 +482,24 @@ class TestDevelocityInjection extends BaseInitScriptTest {
assert 1 == result.output.count(enforceUrl)
}
void outputContainsRemoteBuildCacheConfiguration(BuildResult result, String server, String path, boolean enabled, boolean push) {
def remoteBuildCacheInfo = "Configuring the remote build cache: $server, path: $path, enabled: $enabled, push: $push, allowInsecureProtocol: false, allowUntrustedServer: <default>"
assert result.output.contains(remoteBuildCacheInfo)
assert 1 == result.output.count(remoteBuildCacheInfo)
}
void outputContainsLocalBuildCacheConfiguration(BuildResult result, boolean enabled, boolean push) {
def localBuildCacheInfo = "Configuring the local build cache: enabled: $enabled, push: $push"
assert result.output.contains(localBuildCacheInfo)
assert 1 == result.output.count(localBuildCacheInfo)
}
void outputReplacesRemoteBuildCache(BuildResult result) {
def replaceRemoteBuildCache = "Replacing the existing remote build cache with the Develocity Build Cache connector"
assert result.output.contains(replaceRemoteBuildCache)
assert 1 == result.output.count(replaceRemoteBuildCache)
}
private BuildResult run(TestGradleVersion testGradleVersion, TestConfig config, List<String> args = ["help"]) {
return run(args, initScript, testGradleVersion.gradleVersion, config.jvmArgs, config.envVars)
}
@@ -457,6 +516,12 @@ class TestDevelocityInjection extends BaseInitScriptTest {
String pluginRepositoryUsername = null
String pluginRepositoryPassword = null
boolean captureFileFingerprints = false
boolean enforceBuildCache = false
Boolean remoteBuildCacheEnabled = null
Boolean remoteBuildCachePush = null
String remoteBuildCacheServer = null
String remoteBuildCachePath = null
Boolean localBuildCacheEnabled = null
String develocityPluginVersion
TestConfig(String develocityPluginVersion) {
@@ -490,6 +555,28 @@ class TestDevelocityInjection extends BaseInitScriptTest {
return this
}
TestConfig withRemoteBuildCache(boolean enabled = true, boolean push = true) {
this.remoteBuildCacheEnabled = enabled
this.remoteBuildCachePush = push
return this
}
TestConfig withRemoteBuildCacheLocation(String server, String path) {
this.remoteBuildCacheServer = server
this.remoteBuildCachePath = path
return this
}
TestConfig withLocalBuildCache(boolean enabled = true) {
this.localBuildCacheEnabled = enabled
return this
}
TestConfig withEnforceBuildCache() {
this.enforceBuildCache = true
return this
}
def getEnvVars() {
Map<String, String> envVars = [
DEVELOCITY_INJECTION_INIT_SCRIPT_NAME : "gradle-actions.inject-develocity.init.gradle",
@@ -507,6 +594,12 @@ class TestDevelocityInjection extends BaseInitScriptTest {
if (pluginRepositoryUrl != null) envVars.put("DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_URL", pluginRepositoryUrl)
if (pluginRepositoryUsername != null) envVars.put("DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_USERNAME", pluginRepositoryUsername)
if (pluginRepositoryPassword != null) envVars.put("DEVELOCITY_INJECTION_PLUGIN_REPOSITORY_PASSWORD", pluginRepositoryPassword)
if (enforceBuildCache) envVars.put("DEVELOCITY_INJECTION_ENFORCE_BUILD_CACHE", "true")
if (remoteBuildCacheEnabled != null) envVars.put("DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_ENABLED", String.valueOf(remoteBuildCacheEnabled))
if (remoteBuildCachePush != null) envVars.put("DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_PUSH", String.valueOf(remoteBuildCachePush))
if (remoteBuildCacheServer != null) envVars.put("DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_SERVER", remoteBuildCacheServer)
if (remoteBuildCachePath != null) envVars.put("DEVELOCITY_INJECTION_REMOTE_BUILD_CACHE_PATH", remoteBuildCachePath)
if (localBuildCacheEnabled != null) envVars.put("DEVELOCITY_INJECTION_LOCAL_BUILD_CACHE_ENABLED", String.valueOf(localBuildCacheEnabled))
return envVars
}
@@ -529,6 +622,12 @@ class TestDevelocityInjection extends BaseInitScriptTest {
if (pluginRepositoryUrl != null) jvmArgs.add("-Ddevelocity-injection.plugin-repository.url=$pluginRepositoryUrl")
if (pluginRepositoryUsername != null) jvmArgs.add("-Ddevelocity-injection.plugin-repository.username=$pluginRepositoryUsername")
if (pluginRepositoryPassword != null) jvmArgs.add("-Ddevelocity-injection.plugin-repository.password=$pluginRepositoryPassword")
if (enforceBuildCache) jvmArgs.add("-Ddevelocity-injection.enforce-build-cache=true")
if (remoteBuildCacheEnabled != null) jvmArgs.add("-Ddevelocity-injection.remote-build-cache.enabled=$remoteBuildCacheEnabled")
if (remoteBuildCachePush != null) jvmArgs.add("-Ddevelocity-injection.remote-build-cache.push=$remoteBuildCachePush")
if (remoteBuildCacheServer != null) jvmArgs.add("-Ddevelocity-injection.remote-build-cache.server=$remoteBuildCacheServer")
if (remoteBuildCachePath != null) jvmArgs.add("-Ddevelocity-injection.remote-build-cache.path=$remoteBuildCachePath")
if (localBuildCacheEnabled != null) jvmArgs.add("-Ddevelocity-injection.local-build-cache.enabled=$localBuildCacheEnabled")
return jvmArgs.collect { it.toString() } // Convert from GStrings
}