Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Apache Kafka Gradle Build Environment

From Leeroopedia


Knowledge Sources
Domains Infrastructure, Build_System
Last Updated 2026-02-09 12:00 GMT

Overview

Gradle 9.2.1 build environment with Scala 2.13.18 compiler and JDK 17+ for building Apache Kafka from source.

Description

The Gradle Build Environment defines the build toolchain for compiling Apache Kafka from source. Gradle 9.2.1 is bundled via the Gradle Wrapper (no separate installation required). The build targets two Java versions: Java 11 for client modules and Java 17 for all other modules, using the `--release` compiler flag. Scala 2.13.18 is the default Scala version. The build allocates up to 4GB heap for Gradle (`-Xmx4g`) with parallel GC, and test forks are limited to the number of available CPU cores (configurable via `maxParallelForks`). The Scala optimizer defaults to `inline-kafka` mode for production builds.

Usage

Use this environment for building Kafka from source, running tests, generating release artifacts, and publishing to Maven repositories. The Gradle build is required as a precursor to the Release Candidate Staging workflow (for `./gradlew releaseTarGz`) and for local development.

System Requirements

Category Requirement Notes
OS Linux, macOS, or Windows Cross-platform via Gradle Wrapper
Java JDK 17+ Required for compilation; clients target Java 11 via `--release`
RAM 4GB+ available Gradle JVM args: `-Xmx4g`
Disk 2GB+ free space For build output and Gradle cache
Network Internet access (first build) Downloads dependencies; offline after cache is populated

Dependencies

Build Tools

  • Gradle 9.2.1 (bundled via wrapper; SHA256: `72f44c9f8ebcb1af43838f45ee5c4aa9c5444898b3468ab3f4af7b6076c5bc3f`)
  • Scala 2.13.18 (default)

Gradle Plugins

  • `com.github.ben-manes.versions` 0.53.0
  • `org.owasp.dependencycheck` 12.1.8
  • `org.nosphere.apache.rat` 0.8.1
  • `com.github.spotbugs` 6.4.4
  • `org.scoverage` 8.1
  • `com.gradleup.shadow` 8.3.9
  • `com.diffplug.spotless` 8.0.0

Credentials

The following may be needed for specific build tasks:

  • `mavenUrl`: Maven repository URL for publishing (Gradle property).
  • `mavenUsername`: Maven repository username (Gradle property).
  • `mavenPassword`: Maven repository password (Gradle property).

Quick Install

# Build Kafka (Gradle Wrapper handles Gradle installation)
./gradlew jar

# Run all tests
./gradlew test

# Build release tarball
./gradlew releaseTarGz

# Build with custom Scala optimizer mode
./gradlew jar -PscalaOptimizerMode=inline-scala

Code Evidence

Gradle version from `gradle/wrapper/gradle-wrapper.properties:4`:

distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
distributionSha256Sum=72f44c9f8ebcb1af43838f45ee5c4aa9c5444898b3468ab3f4af7b6076c5bc3f

Java version configuration from `build.gradle:47-49`:

ext {
  minClientJavaVersion = 11
  minNonClientJavaVersion = 17
}

JVM args and parallelism from `build.gradle:53-54,74`:

defaultMaxHeapSize = "2g"
defaultJvmArgs = ["-Xss4m", "-XX:+UseParallelGC"]
// ...
maxTestForks = project.hasProperty('maxParallelForks') ?
  maxParallelForks.toInteger() : Runtime.runtime.availableProcessors()

Scala optimizer modes from `build.gradle:105-109`:

userScalaOptimizerMode = project.hasProperty("scalaOptimizerMode") ?
  scalaOptimizerMode : "inline-kafka"
def scalaOptimizerValues = ["none", "method", "inline-kafka", "inline-scala"]

Common Errors

Error Message Cause Solution
`Could not determine java version from '...'` Unsupported JDK version Use JDK 17 or later
`java.lang.OutOfMemoryError: Java heap space` Insufficient heap for Gradle Increase `org.gradle.jvmargs` in `gradle.properties` (default: `-Xmx4g`)
`Unexpected value for scalaOptimizerMode` Invalid optimizer mode Use one of: `none`, `method`, `inline-kafka`, `inline-scala`
`Unexpected value for keepAliveMode` Invalid keep-alive mode Use valid KeepAliveMode value (default: `daemon`)

Compatibility Notes

  • Scala Version: Default is 2.13.18. Overridable via `SCALA_VERSION` environment variable or `-PscalaVersion` Gradle property.
  • Parallel Testing: Defaults to number of CPU cores. Override with `-PmaxParallelForks=N` for constrained environments.
  • Scala Optimizer: `inline-kafka` is the recommended default. `inline-scala` inlines more aggressively but increases build time.
  • CI/CD: The build detects `GITHUB_ACTIONS` environment variable and adjusts Gradle Enterprise (Develocity) reporting accordingly.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment