Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ Vagrantfile.local
config/server-*
config/zookeeper-*
core/data/*
gradle/wrapper/*
gradlew
gradle/wrapper/*.jar
gradlew.bat

results
Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ Apache Kafka
=================
See our [web site](http://kafka.apache.org) for details on the project.

You need to have [Gradle](http://www.gradle.org/installation) and [Java](http://www.oracle.com/technetwork/java/javase/downloads/index.html) installed.

Kafka requires Gradle 5.0 or higher.
You need to have [Java](http://www.oracle.com/technetwork/java/javase/downloads/index.html) installed.

Java 8 should be used for building in order to support both Java 8 and Java 11 at runtime.

Scala 2.12 is used by default, see below for how to use a different Scala version or all of the supported Scala versions.

### First bootstrap and download the wrapper ###
cd kafka_source_dir
gradle

Now everything else will work.

### Build a jar and run it ###
./gradlew jar

Expand Down
19 changes: 19 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
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
199 changes: 199 additions & 0 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 103 additions & 4 deletions wrapper.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

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.

// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 distributionUrl in the gradle-wrapper.properties, right? That would make sure to always use the correct version of gradle.
I think perhaps we could make a comment there that people should not expect the distributionUrl to work anymore, neither gradle wrapper --gradle-version x.y as they'd expect.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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 gradlew script to support downloading the wrapper jar if it doesn't exist. That jar is technically gradle version agnostic. It hasn't changed for a very long time.

Running the gradle wrapper task will still output a gradle/wrapper/gradle-wrapper.properties file and passing --gradle-version x.y.x, distribution-type=foo or --gradle-distribution-url=bar will all still override the task defaults.

// 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.