Skip to content

Conversation

joshua2519
Copy link
Contributor

@joshua2519 joshua2519 commented Oct 8, 2025

According to the
discussion
in #19513 , add a new checksum verification process to determine whether
a new wrapper JAR needs to be downloaded.

This prevents developers from running into incompatibility issues when
using an outdated wrapper JAR after a Gradle upgrade.

Reviewers: Chia-Ping Tsai [email protected]

@github-actions github-actions bot added triage PRs from the community build Gradle build or GitHub Actions small Small PRs labels Oct 8, 2025
@chia7712
Copy link
Member

chia7712 commented Oct 8, 2025

Th PR description is not correct. We don't want to revert whole changes. Als, please reference to the conversation

@joshua2519
Copy link
Contributor Author

Th PR description is not correct. We don't want to revert whole changes. Als, please reference to the conversation

Done

@chia7712
Copy link
Member

chia7712 commented Oct 8, 2025

@joshua2519 I have another idea that we could check the sha256sum of gradle-wrapper.jar first. If it is not the latest version, we delete it and then re-download. WDYT?

@joshua2519 joshua2519 changed the title MINOR: Revert JVM options and CLASSPATH in gradlew MINOR: verifying the wrapper JAR version in gradlew Oct 10, 2025
@joshua2519 joshua2519 changed the title MINOR: verifying the wrapper JAR version in gradlew MINOR: new checksum verification in gradlew Oct 10, 2025
@joshua2519
Copy link
Contributor Author

joshua2519 commented Oct 10, 2025

@joshua2519 I have another idea that we could check the sha256sum of gradle-wrapper.jar first. If it is not the latest version, we delete it and then re-download. WDYT?

@chia7712
That's a great idea!
I've added a checksum verification process. Now, if the local version of the gradle-wrapper.jar doesn't match the project's required Gradle version, the local JAR file will be deleted, forcing a download of the new version.

wrapper.gradle Outdated

def bootstrapString = """
# Loop in case we encounter an error.
REQUIRED_WRAPPER_JAR_CHECKSUM=\$(curl -sSL "$wrapperJarChecksumUrl")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please hardcode the sha?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that. Considering that Gradle version updates are infrequent, hardcoding the SHA is a much more efficient method than retrieving the checksum every time. I've included a code comment to ensure the checksum is also updated whenever we perform a Gradle version upgrade.

wrapper.gradle Outdated
continue
fi
else
# Verify checksum of existing wrapper JAR.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments explaining the reason for adding this mechanism

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

sleep 5
continue
fi
else
Copy link
Member

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?

Copy link
Contributor Author

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?

@github-actions github-actions bot removed the triage PRs from the community label Oct 11, 2025
if [ "\$LOCAL_WRAPPER_JAR_CHECKSUM" != "\$REQUIRED_WRAPPER_JAR_CHECKSUM" ] ; then
rm -f "$wrapperJarPath"
else
break
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712
The loop will break once the JAR file exists and the checksum matches.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if users' local machine can't use either sha256sum or shasum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712
Thank you for pointing that out.
If no checksum tool is found, exit with an error.

gradlew Outdated
LOCAL_WRAPPER_JAR_CHECKSUM=$(shasum -a 256 "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" | awk '{print $1}')
else
# If no checksum tool is found, exit with an error.
die "ERROR: Cannot find sha256sum or shasum to verify wrapper JAR. Please install one of these tools."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just skip the sha check if there is no available tool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

wrapper.gradle Outdated
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, exit with an error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no checksum tool is found, exit with an error. this comment is out-of-date, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. I have fixed it.

@joshua2519
Copy link
Contributor Author

joshua2519 commented Oct 17, 2025

I have completed the following tests locally:

  1. Executing ./gradlew in an environment without sha256sum and shasum displays a warn message.
  2. After manually downloading an old version of the wrapper JAR, executing ./gradlew results in the new version of the JAR file being re-downloaded.

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please merge wrapperBaseUrl with wrapperJarUrl and then move wrapperChecksum up to line#41? Doing so would remind future developers to update both variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@chia7712 chia7712 merged commit db1ee63 into apache:trunk Oct 17, 2025
24 checks passed
JimmyWang6 pushed a commit to JimmyWang6/jimmy-KAFKA-14048 that referenced this pull request Oct 19, 2025
According to the

[discussion](apache#19513 (comment))
in apache#19513 , add a new checksum verification process to determine whether
a new  wrapper JAR needs to be downloaded.

This prevents developers  from running into incompatibility issues when
using an outdated wrapper  JAR after a Gradle upgrade.

Reviewers: Chia-Ping Tsai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Gradle build or GitHub Actions ci-approved small Small PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants