-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-1714: Fix gradle wrapper bootstrapping #6031
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 5 commits
9231b33
829841a
0e9e7bc
fe903f3
0207db1
b7e785a
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # | ||
| # Copyright 2017 the original author or authors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,108 @@ | |
| * under the License. | ||
| */ | ||
|
|
||
| defaultTasks 'downloadWrapper' | ||
| // This file contains tasks for the gradle wrapper generation. | ||
|
|
||
| task downloadWrapper(type: Wrapper) { | ||
| description = "Download the gradle wrapper and requisite files. Overwrites existing wrapper files." | ||
| // Ensure the wrapper script is generated based on the version defined in the project | ||
| // and not the version installed on the machine running the task. | ||
| // Read more about the wrapper here: https://docs.gradle.org/current/userguide/gradle_wrapper.html | ||
| wrapper { | ||
| gradleVersion = project.gradleVersion | ||
| } | ||
| distributionType = Wrapper.DistributionType.ALL | ||
| } | ||
|
|
||
| def licenseString = """# | ||
| # Copyright 2017 the original author or authors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License.""" | ||
|
|
||
| // Custom task to inject support for downloading the gradle wrapper jar if it doesn't exist. | ||
| // This allows us to avoid checking in the jar to our repository. | ||
| // Additionally adds a license header to the wrapper while editing the file contents. | ||
| task bootstrapWrapper() { | ||
| // In the doLast block so this runs when the task is called and not during project configuration. | ||
| doLast { | ||
| def wrapperBasePath = "\$APP_HOME/gradle/wrapper" | ||
| def wrapperJarPath = wrapperBasePath + "/gradle-wrapper.jar" | ||
|
|
||
| // Add a trailing zero to the version if needed. | ||
| def fullVersion = project.gradleVersion.count(".") == 1 ? "${project.gradleVersion}.0" : versions.gradle | ||
|
Contributor
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. If I understand correctly here you would use the project's gradle version instead of the
Member
Author
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. All of those things would still work as expected and as it did before. What this patch does is edit the Running the |
||
| // Leverages the wrapper jar checked into the gradle project on github because the jar isn't | ||
| // available elsewhere. Using raw.githubusercontent.com instead of github.com because | ||
| // 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$fullVersion/gradle/wrapper" | ||
| def wrapperJarUrl = wrapperBaseUrl + "/gradle-wrapper.jar" | ||
|
|
||
| def bootstrapString = """ | ||
| # Loop in case we encounter an error. | ||
| for attempt in 1 2 3; do | ||
| if [ ! -e $wrapperJarPath ]; then | ||
| if ! curl -s -S --retry 3 -L -o "$wrapperJarPath" "$wrapperJarUrl"; then | ||
| rm -f "$wrapperJarPath" | ||
| # Pause for a bit before looping in case the server throttled us. | ||
| sleep 5 | ||
| continue | ||
| fi | ||
| fi | ||
| done | ||
| """.stripIndent() | ||
|
|
||
| def wrapperScript = wrapper.scriptFile | ||
| def wrapperLines = wrapperScript.readLines() | ||
| wrapperScript.withPrintWriter { out -> | ||
| def licenseWritten = false | ||
| def bootstrapWritten = false | ||
| wrapperLines.each { line -> | ||
| // Print the wrapper bootstrap before the first usage of the wrapper jar. | ||
| if (!bootstrapWritten && line.contains("gradle-wrapper.jar")) { | ||
| out.println(bootstrapString) | ||
| bootstrapWritten = true | ||
| } | ||
| out.print(line) | ||
| // Print the licence after the shebang. | ||
| if(!licenseWritten && line.contains("#!/usr/bin/env sh")) { | ||
| out.println() | ||
| out.print(licenseString) | ||
| licenseWritten = true | ||
| } | ||
| out.println() // New Line | ||
| } | ||
| } | ||
| } | ||
| } | ||
| wrapper.finalizedBy bootstrapWrapper | ||
|
|
||
| // Custom task to add a license header to the gradle-wrapper.properties file. | ||
| task bootstrapWrapperProperties() { | ||
| // In the doLast block so this runs when the task is called and not during project configuration. | ||
| doLast { | ||
| def wrapperProperties = wrapper.propertiesFile | ||
| def wrapperLines = wrapperProperties.readLines() | ||
| wrapperProperties.withPrintWriter { out -> | ||
| // Print the license | ||
| out.println(licenseString) | ||
| wrapperLines.each { line -> | ||
| out.println(line) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| wrapper.finalizedBy bootstrapWrapperProperties | ||
|
|
||
| // Remove the generated batch file since we don't test building in the Windows environment. | ||
| task removeWindowsScript(type: Delete) { | ||
| delete "$rootDir/gradlew.bat" | ||
| } | ||
| wrapper.finalizedBy removeWindowsScript | ||
|
Member
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. Hmm, people do seem to build on Windows even if we don't support it. Should we keep this?
Member
Author
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. Users could still build with a local install of gradle, they just can't use the wrapper. Given we don't support it, I don't want to do more work to make it easier.
Member
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. Does that mean that we need different instructions for Windows? Given the number of complaints we get from Windows users, I think we should not make things worse for them if we can avoid it. If you have concerns about this working for Windows users, we could simply state in the README that they have to do it the old way. |
||
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.
Did you remove the jar too?
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.
The jar shouldn't be removed, just not checked in. The .gitignore entry handles this.