README.md 11.5 KB
Newer Older
1 2
Apache Kafka
=================
3
See our [web site](https://kafka.apache.org) for details on the project.
4

5
You need to have [Java](http://www.oracle.com/technetwork/java/javase/downloads/index.html) installed.
6

7
We build and test Apache Kafka with Java 8, 11 and 15. We set the `release` parameter in javac and scalac
8 9
to `8` to ensure the generated binaries are compatible with Java 8 or higher (independently of the Java version
used for compilation).
10

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

13
### Build a jar and run it ###
D
David Chen 已提交
14
    ./gradlew jar
15

16
Follow instructions in https://kafka.apache.org/quickstart
17

18
### Build source jar ###
19 20
    ./gradlew srcJar

21
### Build aggregated javadoc ###
22 23
    ./gradlew aggregatedJavadoc

24
### Build javadoc and scaladoc ###
25
    ./gradlew javadoc
26
    ./gradlew javadocJar # builds a javadoc jar for each module
27
    ./gradlew scaladoc
28 29
    ./gradlew scaladocJar # builds a scaladoc jar for each module
    ./gradlew docsJar # builds both (if applicable) javadoc and scaladoc jars for each module
30

31 32 33 34 35 36
### Run unit/integration tests ###
    ./gradlew test # runs both unit and integration tests
    ./gradlew unitTest
    ./gradlew integrationTest
    
### Force re-running tests without code change ###
37
    ./gradlew cleanTest test
38 39
    ./gradlew cleanTest unitTest
    ./gradlew cleanTest integrationTest
40

41
### Running a particular unit/integration test ###
42
    ./gradlew clients:test --tests RequestResponseTest
43

44
### Running a particular test method within a unit/integration test ###
45 46
    ./gradlew core:test --tests kafka.api.ProducerFailureHandlingTest.testCannotSendToInternalTopic
    ./gradlew clients:test --tests org.apache.kafka.clients.MetadataTest.testMetadataUpdateWaitTime
47

48
### Running a particular unit/integration test with log4j output ###
I
Ismael Juma 已提交
49 50
Change the log4j setting in either `clients/src/test/resources/log4j.properties` or `core/src/test/resources/log4j.properties`

51
    ./gradlew clients:test --tests RequestResponseTest
52

53 54 55 56 57 58 59
### Specifying test retries ###
By default, each failed test is retried once up to a maximum of five retries per test run. Tests are retried at the end of the test task. Adjust these parameters in the following way:

    ./gradlew test -PmaxTestRetries=1 -PmaxTestRetryFailures=5
    
See [Test Retry Gradle Plugin](https://github.com/gradle/test-retry-gradle-plugin) for more details.

60
### Generating test coverage reports ###
61 62
Generate coverage reports for the whole project:

63
    ./gradlew reportCoverage -PenableTestCoverage=true -Dorg.gradle.parallel=false
64

65 66
Generate coverage for a single module, i.e.: 

67
    ./gradlew clients:reportCoverage -PenableTestCoverage=true -Dorg.gradle.parallel=false
68
    
69
### Building a binary release gzipped tar ball ###
70
    ./gradlew clean releaseTarGz
I
Ismael Juma 已提交
71 72

The release file can be found inside `./core/build/distributions/`.
73

74 75 76 77 78 79
### Building auto generated messages ###
Sometimes it is only necessary to rebuild the RPC auto-generated message data when switching between branches, as they could
fail due to code changes. You can just run:
 
    ./gradlew processMessages processTestMessages

80
### Running a Kafka broker in ZooKeeper mode
81 82 83 84

    ./bin/zookeeper-server-start.sh config/zookeeper.properties
    ./bin/kafka-server-start.sh config/server.properties

85
### Running a Kafka broker in KRaft (Kafka Raft metadata) mode
86

87
See [config/kraft/README.md](https://github.com/apache/kafka/blob/trunk/config/kraft/README.md).
88

89 90 91
### Cleaning the build ###
    ./gradlew clean

92
### Running a task with one of the Scala versions available (2.12.x or 2.13.x) ###
93
*Note that if building the jars with a version other than 2.13.x, you need to set the `SCALA_VERSION` variable or change it in `bin/kafka-run-class.sh` to run the quick start.*
94 95 96 97 98 99

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
I
Ismael Juma 已提交
100

101
### Running a task with all the scala versions enabled by default ###
I
Ismael Juma 已提交
102

103
Invoke the `gradlewAll` script followed by the task(s):
104

105 106 107
    ./gradlewAll test
    ./gradlewAll jar
    ./gradlewAll releaseTarGz
108 109

### Running a task for a specific project ###
I
Ismael Juma 已提交
110 111
This is for `core`, `examples` and `clients`

112 113
    ./gradlew core:jar
    ./gradlew core:test
114

115 116 117 118
Streams has multiple sub-projects, but you can run all the tests:

    ./gradlew :streams:testAll

119 120
### Listing all gradle tasks ###
    ./gradlew tasks
121

122
### Building IDE project ####
I
Ismael Juma 已提交
123 124
*Note that this is not strictly necessary (IntelliJ IDEA has good built-in support for Gradle projects, for example).*

125 126
    ./gradlew eclipse
    ./gradlew idea
127

128 129 130 131
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.

132
### Publishing the jar for all version of Scala and for all projects to maven ###
133 134 135 136 137 138
The recommended command is:

    ./gradlewAll publish

For backwards compatibility, the following also works:

139
    ./gradlewAll uploadArchives
140

141
Please note for this to work you should create/update `${GRADLE_USER_HOME}/gradle.properties` (typically, `~/.gradle/gradle.properties`) and assign the following variables
142

143 144 145 146 147 148
    mavenUrl=
    mavenUsername=
    mavenPassword=
    signing.keyId=
    signing.password=
    signing.secretKeyRingFile=
149

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
### 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>
     ...


180
### Installing the jars to the local Maven repository ###
181 182 183 184 185 186
The recommended command is:

    ./gradlewAll publishToMavenLocal

For backwards compatibility, the following also works:

187
    ./gradlewAll install
188

189 190
### Building the test jar ###
    ./gradlew testJar
191

192 193
### Determining how transitive dependencies are added ###
    ./gradlew core:dependencies --configuration runtime
I
Ismael Juma 已提交
194

195 196 197
### Determining if any dependencies could be updated ###
    ./gradlew dependencyUpdates

198
### Running code quality checks ###
199
There are two code quality analysis tools that we regularly run, spotbugs and checkstyle.
200

201
#### Checkstyle ####
202 203 204
Checkstyle enforces a consistent coding style in Kafka.
You can run checkstyle using:

205
    ./gradlew checkstyleMain checkstyleTest
206

207
The checkstyle warnings will be found in `reports/checkstyle/reports/main.html` and `reports/checkstyle/reports/test.html` files in the
208
subproject build directories. They are also printed to the console. The build will fail if Checkstyle fails.
209

210 211 212
#### Spotbugs ####
Spotbugs uses static analysis to look for bugs in the code.
You can run spotbugs using:
213

214
    ./gradlew spotbugsMain spotbugsTest -x test
215

216 217
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.
218

219 220 221 222 223
### JMH microbenchmarks ###
We use [JMH](https://openjdk.java.net/projects/code-tools/jmh/) to write microbenchmarks that produce reliable results in the JVM.
    
See [jmh-benchmarks/README.md](https://github.com/apache/kafka/blob/trunk/jmh-benchmarks/README.md) for details on how to run the microbenchmarks.

224 225
### Common build options ###

226
The following options should be set with a `-P` switch, for example `./gradlew -PmaxParallelForks=1 test`.
227

M
Max Zheng 已提交
228
* `commitId`: sets the build commit ID as .git/HEAD might not be correct if there are local commits added for build purposes.
229 230
* `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.
231
* `ignoreFailures`: ignore test failures from junit
232 233 234
* `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`.
235
* `xmlSpotBugsReport`: enable XML reports for spotBugs. This also disables HTML reports as only one can be enabled at a time.
236 237
* `maxTestRetries`: the maximum number of retries for a failing test case.
* `maxTestRetryFailures`: maximum number of test failures before retrying is disabled for subsequent tests.
238 239 240
* `enableTestCoverage`: enables test coverage plugins and tasks, including bytecode enhancement of classes required to track said
coverage. Note that this introduces some overhead when running tests and hence why it's disabled by default (the overhead
varies, but 15-20% is a reasonable estimate).
241 242 243 244 245 246 247
* `scalaOptimizerMode`: configures the optimizing behavior of the scala compiler, the value should be one of `none`, `method`, `inline-kafka` or
`inline-scala` (the default is `inline-kafka`). `none` is the scala compiler default, which only eliminates unreachable code. `method` also
includes method-local optimizations. `inline-kafka` adds inlining of methods within the kafka packages. Finally, `inline-scala` also
includes inlining of methods within the scala library (which avoids lambda allocations for methods like `Option.exists`). `inline-scala` is
only safe if the Scala library version is the same at compile time and runtime. Since we cannot guarantee this for all cases (for example, users
may depend on the kafka jar for integration tests where they may include a scala library with a different version), we don't enable it by
default. See https://www.lightbend.com/blog/scala-inliner-optimizer for more details.
248

249 250 251 252 253 254 255 256 257 258 259 260
### Dependency Analysis ###

The gradle [dependency debugging documentation](https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html) mentions using the `dependencies` or `dependencyInsight` tasks to debug dependencies for the root project or individual subprojects.

Alternatively, use the `allDeps` or `allDepInsight` tasks for recursively iterating through all subprojects:

    ./gradlew allDeps

    ./gradlew allDepInsight --configuration runtime --dependency com.fasterxml.jackson.core:jackson-databind

These take the same arguments as the builtin variants.

261 262 263 264
### Running system tests ###

See [tests/README.md](tests/README.md).

265 266 267 268
### Running in Vagrant ###

See [vagrant/README.md](vagrant/README.md).

269
### Contribution ###
270

271
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).
272 273

To contribute follow the instructions here:
274
 * https://kafka.apache.org/contributing.html