Skip to content

Verify the Gradle distribution that the wrapper downloads against its SHA-256 - #31

Merged
lagergren merged 1 commit into
masterfrom
gradle-distribution-checksum
Nov 23, 2026
Merged

lagergren merged 1 commit into
masterfrom
gradle-distribution-checksum

Conversation

@lagergren

Copy link
Copy Markdown
Contributor

What

Adds distributionSha256Sum for Gradle 9.9.2 to gradle/wrapper/gradle-wrapper.properties. ./gradlew then verifies the distribution it downloads against Gradle's published checksum, gradle-9.9.2-bin.zip.sha256, and refuses one that doesn't match. That applies to every download, locally and in CI. A distribution already unpacked in a Gradle home isn't checked again.

Why

CI already validates the wrapper (setup-gradle with validate-wrappers: true). That check compares the committed gradle-wrapper.jar with Gradle's checksums. It doesn't cover the distribution that the JAR then downloads, which is what the checksum covers.

Upgrading Gradle from now on

The upgrade has to give the new version's checksum:

./gradlew wrapper --gradle-version <version> \
  --gradle-distribution-sha256-sum "$(curl -fsSL https://services.gradle.org/distributions/gradle-<version>-bin.zip.sha256)"

Without --gradle-distribution-sha256-sum, the wrapper task fails and leaves the file as it was: gradle-wrapper.properties contains distributionSha256Sum property, but the wrapper configuration does not have one. Changing only distributionUrl by hand fails the next download with Verification of Gradle distribution failed!

Base

Stacked on #28, the upgrade to Gradle 9.9.2 that this checksum is for. Once #28 merges, GitHub retargets this PR to master.

Test

  • ./gradlew --version with an empty GRADLE_USER_HOME: the wrapper downloads gradle-9.9.2-bin.zip, verifies it and runs Gradle 9.9.2.
  • With the checksum's last digit changed, the same run fails with Verification of Gradle distribution failed!
  • ./gradlew wrapper --gradle-version 9.9.1 without a checksum fails as described above.

The last two ran in xtc-app-template; they test the wrapper's own checks, which are the same in all three repositories.

… SHA-256

gradle-wrapper.properties gets distributionSha256Sum for Gradle 9.9.2, Gradle's published
gradle-9.9.2-bin.zip.sha256, so ./gradlew refuses a downloaded distribution that doesn't match. CI's
validate-wrappers checks the committed gradle-wrapper.jar, not the distribution that it downloads.

A Gradle upgrade now has to give the new version's checksum: ./gradlew wrapper --gradle-version alone fails, and
leaves the file as it was.

Validated: ./gradlew --version with an empty GRADLE_USER_HOME downloads, verifies and runs Gradle 9.9.2; with the
checksum's last digit changed, it fails with "Verification of Gradle distribution failed!"; ./gradlew wrapper
--gradle-version 9.9.1 without a checksum fails.
@lagergren
lagergren force-pushed the gradle-distribution-checksum branch from 67492f1 to 56fd12f Compare November 23, 2026 16:37
@lagergren
lagergren merged commit 4aa6cd7 into master Nov 23, 2026
1 check passed
@lagergren
lagergren deleted the gradle-distribution-checksum branch November 23, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant