2014-02-14 11:45:53 +08:00
Apache Kafka
=================
2019-04-23 02:58:25 +08:00
See our [web site ](https://kafka.apache.org ) for details on the project.
2011-08-02 07:41:24 +08:00
2019-04-23 02:58:25 +08:00
You need to have [Gradle ](https://www.gradle.org/installation ) and [Java ](https://www.oracle.com/technetwork/java/javase/downloads/index.html ) installed.
2015-12-16 02:55:24 +08:00
2018-12-18 08:30:14 +08:00
Kafka requires Gradle 5.0 or higher.
2016-01-27 07:33:48 +08:00
2018-10-29 02:31:39 +08:00
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.
2014-09-24 00:06:17 +08:00
### First bootstrap and download the wrapper ###
2014-09-24 05:39:10 +08:00
cd kafka_source_dir
2014-09-24 00:06:17 +08:00
gradle
2015-12-16 02:55:24 +08:00
Now everything else will work.
2014-09-24 00:06:17 +08:00
2017-03-21 17:55:46 +08:00
### Build a jar and run it ###
2016-09-15 01:38:40 +08:00
./gradlew jar
2011-08-02 07:41:24 +08:00
2019-04-23 02:58:25 +08:00
Follow instructions in https://kafka.apache.org/documentation.html#quickstart
2011-08-02 07:41:24 +08:00
2017-03-21 17:55:46 +08:00
### Build source jar ###
2014-04-19 04:10:34 +08:00
./gradlew srcJar
2017-03-21 17:55:46 +08:00
### Build aggregated javadoc ###
2016-05-19 07:44:31 +08:00
./gradlew aggregatedJavadoc
2017-03-21 17:55:46 +08:00
### Build javadoc and scaladoc ###
2014-04-19 04:10:34 +08:00
./gradlew javadoc
2016-05-19 07:44:31 +08:00
./gradlew javadocJar # builds a javadoc jar for each module
2014-04-19 04:10:34 +08:00
./gradlew scaladoc
2016-05-19 07:44:31 +08:00
./gradlew scaladocJar # builds a scaladoc jar for each module
./gradlew docsJar # builds both (if applicable) javadoc and scaladoc jars for each module
2014-04-19 04:10:34 +08:00
2017-03-21 17:55:46 +08:00
### Run unit/integration tests ###
./gradlew test # runs both unit and integration tests
./gradlew unitTest
./gradlew integrationTest
### Force re-running tests without code change ###
2014-02-14 11:45:53 +08:00
./gradlew cleanTest test
2017-03-21 17:55:46 +08:00
./gradlew cleanTest unitTest
./gradlew cleanTest integrationTest
2014-02-14 11:45:53 +08:00
2017-03-21 17:55:46 +08:00
### Running a particular unit/integration test ###
2018-11-30 08:04:39 +08:00
./gradlew clients:test --tests RequestResponseTest
2014-02-14 11:45:53 +08:00
2017-03-21 17:55:46 +08:00
### Running a particular test method within a unit/integration test ###
2015-10-19 13:45:27 +08:00
./gradlew core:test --tests kafka.api.ProducerFailureHandlingTest.testCannotSendToInternalTopic
./gradlew clients:test --tests org.apache.kafka.clients.MetadataTest.testMetadataUpdateWaitTime
2015-01-26 11:15:51 +08:00
2017-03-21 17:55:46 +08:00
### Running a particular unit/integration test with log4j output ###
2015-12-16 02:55:24 +08:00
Change the log4j setting in either `clients/src/test/resources/log4j.properties` or `core/src/test/resources/log4j.properties`
2018-11-30 08:04:39 +08:00
./gradlew clients:test --tests RequestResponseTest
2014-03-01 05:53:37 +08:00
2016-04-01 01:07:54 +08:00
### Generating test coverage reports ###
2017-02-11 01:15:12 +08:00
Generate coverage reports for the whole project:
2016-04-01 01:07:54 +08:00
./gradlew reportCoverage
2017-02-11 01:15:12 +08:00
Generate coverage for a single module, i.e.:
./gradlew clients:reportCoverage
2014-02-14 11:45:53 +08:00
### Building a binary release gzipped tar ball ###
2018-10-29 02:31:39 +08:00
./gradlew clean releaseTarGz
2015-12-16 02:55:24 +08:00
The above command will fail if you haven't set up the signing key. To bypass signing the artifact, you can run:
2018-10-29 02:31:39 +08:00
./gradlew clean releaseTarGz -x signArchives
2011-08-02 07:41:24 +08:00
2015-12-16 02:55:24 +08:00
The release file can be found inside `./core/build/distributions/` .
2014-02-08 05:48:04 +08:00
2014-02-14 11:45:53 +08:00
### Cleaning the build ###
./gradlew clean
2018-10-29 02:31:39 +08:00
### Running a task with a particular version of Scala (either 2.11.x or 2.12.x) ###
*Note that if building the jars with a version other than 2.12.x, you need to set the `SCALA_VERSION` variable or change it in `bin/kafka-run-class.sh` to run the quick start.*
You can pass either the major version (eg 2.12) or the full version (eg 2.12.7):
./gradlew -PscalaVersion=2.12 jar
./gradlew -PscalaVersion=2.12 test
./gradlew -PscalaVersion=2.12 releaseTarGz
2015-12-16 02:55:24 +08:00
2018-10-29 02:31:39 +08:00
### Running a task with all scala versions ###
2015-12-16 02:55:24 +08:00
2018-10-29 02:31:39 +08:00
Append `All` to the task name:
./gradlew testAll
./gradlew jarAll
./gradlew releaseTarGzAll
2014-02-14 11:45:53 +08:00
### Running a task for a specific project ###
2015-12-16 02:55:24 +08:00
This is for `core` , `examples` and `clients`
2014-02-14 11:45:53 +08:00
./gradlew core:jar
./gradlew core:test
2014-02-08 05:48:04 +08:00
2014-02-14 11:45:53 +08:00
### Listing all gradle tasks ###
./gradlew tasks
2014-02-08 05:48:04 +08:00
2014-02-14 11:45:53 +08:00
### Building IDE project ####
2015-12-16 02:55:24 +08:00
*Note that this is not strictly necessary (IntelliJ IDEA has good built-in support for Gradle projects, for example).*
2014-02-14 11:45:53 +08:00
./gradlew eclipse
./gradlew idea
2014-02-08 05:48:04 +08:00
2017-02-10 10:37:32 +08:00
The `eclipse` task has been configured to use `${project_dir}/build_eclipse` as Eclipse's build directory. Eclipse's default
build directory (`${project_dir}/bin`) clashes with Kafka's scripts directory and we don't use Gradle's build directory
to avoid known issues with this configuration.
2014-02-14 11:45:53 +08:00
### Publishing the jar for all version of Scala and for all projects to maven ###
./gradlew uploadArchivesAll
2014-02-08 05:48:04 +08:00
2016-09-18 06:01:32 +08:00
Please note for this to work you should create/update `${GRADLE_USER_HOME}/gradle.properties` (typically, `~/.gradle/gradle.properties` ) and assign the following variables
2014-02-08 05:48:04 +08:00
2014-02-14 11:45:53 +08:00
mavenUrl=
mavenUsername=
mavenPassword=
signing.keyId=
signing.password=
signing.secretKeyRingFile=
2014-02-08 05:48:04 +08:00
2017-08-12 03:19:28 +08:00
### Publishing the streams quickstart archetype artifact to maven ###
For the Streams archetype project, one cannot use gradle to upload to maven; instead the `mvn deploy` command needs to be called at the quickstart folder:
cd streams/quickstart
mvn deploy
Please note for this to work you should create/update user maven settings (typically, `${USER_HOME}/.m2/settings.xml` ) to assign the following variables
< settings xmlns = "http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
< servers >
...
< server >
< id > apache.snapshots.https< / id >
< username > ${maven_username}< / username >
< password > ${maven_password}< / password >
< / server >
< server >
< id > apache.releases.https< / id >
< username > ${maven_username}< / username >
< password > ${maven_password}< / password >
< / server >
...
< / servers >
...
2016-01-09 07:13:14 +08:00
### Installing the jars to the local Maven repository ###
./gradlew installAll
2015-05-30 05:50:45 +08:00
2014-02-14 11:45:53 +08:00
### Building the test jar ###
./gradlew testJar
2014-02-08 05:48:04 +08:00
2014-02-14 11:45:53 +08:00
### Determining how transitive dependencies are added ###
./gradlew core:dependencies --configuration runtime
2015-12-16 02:55:24 +08:00
2016-03-04 07:10:16 +08:00
### Determining if any dependencies could be updated ###
./gradlew dependencyUpdates
2017-03-01 07:04:02 +08:00
### Running code quality checks ###
2018-09-11 04:14:00 +08:00
There are two code quality analysis tools that we regularly run, spotbugs and checkstyle.
2017-03-01 07:04:02 +08:00
2017-03-21 17:55:46 +08:00
#### Checkstyle ####
2017-03-01 07:04:02 +08:00
Checkstyle enforces a consistent coding style in Kafka.
You can run checkstyle using:
2015-02-03 13:36:21 +08:00
./gradlew checkstyleMain checkstyleTest
2011-08-02 07:41:24 +08:00
2017-03-01 07:04:02 +08:00
The checkstyle warnings will be found in `reports/checkstyle/reports/main.html` and `reports/checkstyle/reports/test.html` files in the
subproject build directories. They are also are printed to the console. The build will fail if Checkstyle fails.
2018-09-11 04:14:00 +08:00
#### Spotbugs ####
Spotbugs uses static analysis to look for bugs in the code.
You can run spotbugs using:
2017-03-01 07:04:02 +08:00
2018-09-11 04:14:00 +08:00
./gradlew spotbugsMain spotbugsTest -x test
2017-03-01 07:04:02 +08:00
2018-09-11 04:14:00 +08:00
The spotbugs warnings will be found in `reports/spotbugs/main.html` and `reports/spotbugs/test.html` files in the subproject build
directories. Use -PxmlSpotBugsReport=true to generate an XML report instead of an HTML one.
2015-10-13 09:26:38 +08:00
2016-01-09 07:13:14 +08:00
### Common build options ###
2017-04-21 18:29:22 +08:00
The following options should be set with a `-P` switch, for example `./gradlew -PmaxParallelForks=1 test` .
2016-01-09 07:13:14 +08:00
2017-08-04 06:24:05 +08:00
* `commitId` : sets the build commit ID as .git/HEAD might not be correct if there are local commits added for build purposes.
2017-04-21 18:29:22 +08:00
* `mavenUrl` : sets the URL of the maven deployment repository (`file://path/to/repo` can be used to point to a local repository).
* `maxParallelForks` : limits the maximum number of processes for each task.
* `showStandardStreams` : shows standard out and standard error of the test JVM(s) on the console.
* `skipSigning` : skips signing of artifacts.
* `testLoggingEvents` : unit test events to be logged, separated by comma. For example `./gradlew -PtestLoggingEvents=started,passed,skipped,failed test` .
2018-09-11 04:14:00 +08:00
* `xmlSpotBugsReport` : enable XML reports for spotBugs. This also disables HTML reports as only one can be enabled at a time.
2016-01-09 07:13:14 +08:00
2019-06-14 21:21:38 +08:00
### Running system tests ###
See [tests/README.md ](tests/README.md ).
2014-12-05 21:37:11 +08:00
### Running in Vagrant ###
See [vagrant/README.md ](vagrant/README.md ).
2014-02-14 11:45:53 +08:00
### Contribution ###
2013-07-11 23:06:43 +08:00
2014-09-15 01:16:07 +08:00
Apache Kafka is interested in building the community; we would welcome any thoughts or [patches ](https://issues.apache.org/jira/browse/KAFKA ). You can reach us [on the Apache mailing lists ](http://kafka.apache.org/contact.html ).
2013-07-11 23:06:43 +08:00
To contribute follow the instructions here:
2019-04-23 02:58:25 +08:00
* https://kafka.apache.org/contributing.html