-
Notifications
You must be signed in to change notification settings - Fork 14.7k
MINOR: new checksum verification in gradlew #20658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
461e8e3
c0b0428
002b8ca
199f8f9
3a0fe97
1d95c06
5c93680
673dab0
1512bc9
5cf0f6f
039e08c
3ab92f0
f8fe4cb
0bf201c
4698956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,11 +39,13 @@ task bootstrapWrapper() { | |
// github.com servers deprecated TLSv1/TLSv1.1 support some time ago, so older versions | ||
// of curl (built against OpenSSL library that doesn't support TLSv1.2) would fail to | ||
// fetch the jar. | ||
def wrapperBaseUrl = "https://raw.githubusercontent.com/gradle/gradle/v$versions.gradle/gradle/wrapper" | ||
def wrapperJarUrl = wrapperBaseUrl + "/gradle-wrapper.jar" | ||
// IMPORTANT: This checksum **must** be updated whenever the Gradle version changes. | ||
String wrapperChecksum = "76805e32c009c0cf0dd5d206bddc9fb22ea42e84db904b764f3047de095493f3" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please merge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
def wrapperJarUrl = "https://raw.githubusercontent.com/gradle/gradle/v$versions.gradle/gradle/wrapper/gradle-wrapper.jar" | ||
|
||
def bootstrapString = """ | ||
# Loop in case we encounter an error. | ||
REQUIRED_WRAPPER_JAR_CHECKSUM="$wrapperChecksum" | ||
for attempt in 1 2 3; do | ||
if [ ! -e "$wrapperJarPath" ]; then | ||
if ! curl -s -S --retry 3 -L -o "$wrapperJarPath" "$wrapperJarUrl"; then | ||
|
@@ -52,6 +54,26 @@ task bootstrapWrapper() { | |
sleep 5 | ||
continue | ||
fi | ||
else | ||
# Verify checksum of existing wrapper JAR. | ||
# This prevents developers from running into incompatibility issues when using an outdated wrapper JAR after a Gradle upgrade. | ||
# Use sha256sum or shasum, whichever is available. | ||
if command -v sha256sum >/dev/null 2>&1; then | ||
LOCAL_WRAPPER_JAR_CHECKSUM=\$(sha256sum "$wrapperJarPath" | awk '{print \$1}') | ||
elif command -v shasum >/dev/null 2>&1; then | ||
LOCAL_WRAPPER_JAR_CHECKSUM=\$(shasum -a 256 "$wrapperJarPath" | awk '{print \$1}') | ||
else | ||
# If no checksum tool is found, this verification is skipped . | ||
warn "Cannot find sha256sum or shasum to verify wrapper JAR." | ||
break | ||
fi | ||
|
||
# If the local checksum does not match the required checksum, delete the JAR to force re-download. | ||
if [ "\$LOCAL_WRAPPER_JAR_CHECKSUM" != "\$REQUIRED_WRAPPER_JAR_CHECKSUM" ] ; then | ||
rm -f "$wrapperJarPath" | ||
else | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chia7712 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if users' local machine can't use either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chia7712 |
||
fi | ||
fi | ||
done | ||
""".stripIndent() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch causes the unnecessary loops, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
Could it be better to add a condition to break the loop?