This is an automated email from the ASF dual-hosted git repository.
payang pushed a commit to branch 3.9
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/3.9 by this push:
new 7ac6b3ff338 KAFKA-19897: Support testing with Java 25 using Gradle
Java Toolchains (3.9) (#21026)
7ac6b3ff338 is described below
commit 7ac6b3ff3383177084b32b432223377ec8fc180f
Author: Ming-Yen Chung <[email protected]>
AuthorDate: Mon Dec 8 13:44:04 2025 +0800
KAFKA-19897: Support testing with Java 25 using Gradle Java Toolchains
(3.9) (#21026)
**Motivation:** As discussed in
https://github.com/apache/kafka-site/pull/748
**Changes**:
* Add a new Gradle task `testWithJava25` that allows running unit and
integration tests with Java 25 toolchain without upgrading Gradle
* A direct Gradle upgrade is infeasible: running JDK 25 requires Gradle
9.1+, but Kafka 3.9's dependency on JDK 8 limits the maximum supported
Gradle version to 8.14.
Ref: https://docs.gradle.org/current/userguide/compatibility.html
* Upgrade mockito to support Java 25
We don't use Java 25 toolchain to build the code because builds with JDK
8 or 11 would fail. This is due to `JavaVersion.current()` returning the
Gradle JVM version instead of the toolchain version. Fixing this issue
would require extensive changes throughout the codebase.
---
## Old Information
The following section contains older information from a previous
approach.
If you later decide to allow Java 25 to build the 3.9 code, you may
refer to it.
**Changes**:
* Use Gradle’s Java toolchains instead of upgrading Gradle to enable
building with Java 25.
* Users can specify `-PjavaToolChainVersion=25` in Gradle commands to
select Java toolchain version
* Upgrade SpotBugs to supports Java 25 (4.9.7+).
* Add exclusions for new warnings to allow this upgrade.
* Scala 2.12.x currently does not support Java 25; support will be
available in 2.12.21, expected to be released before the end of
December.
* Upgrade Scala 2.13.15 → 2.13.18, instead of trunk 2.13.17. because
using 2.13.17 causes false errors:
* > Task :core:compileTestScala
[Error]
/Users/ming/code/kafka/core/src/test/scala/unit/kafka/security/authorizer/AuthorizerTest.scala:63:21:
private val KRAFT in class AuthorizerTest is never used
one error found
* This happens because the annotation usage is not detected, like
`@ValueSource(strings = Array(KRAFT, ZK))`
**Usage:**
Note that using JDK 8 or 11 with the -PjavaToolChainVersion flat will
break.
```
> sdk use java 21.0.9-tem
Using java version 21.0.9-tem in this shell.
> ./gradlew clean -PjavaToolChainVersion=25 build
```
---
Jenkinsfile | 20 ++++++++++++++++++++
build.gradle | 35 +++++++++++++++++++++++++++++++++++
gradle/dependencies.gradle | 2 +-
settings.gradle | 2 ++
4 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/Jenkinsfile b/Jenkinsfile
index 0023b76a8e7..10b02abeb51 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -199,6 +199,26 @@ pipeline {
echo 'Skipping Kafka Streams archetype test for Java 23'
}
}
+ stage('JDK 25 and Scala 2.13') {
+ agent { label 'ubuntu' }
+ tools {
+ // Use JDK 21 because Gradle 8 cannot run on JDK 25.
+ // JDK 25 is used only for tests via task testWithJava25 and does
not affect the validation and build.
+ jdk 'jdk_21_latest'
+ }
+ options {
+ timeout(time: 8, unit: 'HOURS')
+ timestamps()
+ }
+ environment {
+ SCALA_VERSION=2.13
+ }
+ steps {
+ doValidation()
+ doTest(env, 'testWithJava25')
+ echo 'Skipping Kafka Streams archetype test for Java 25'
+ }
+ }
}
}
}
diff --git a/build.gradle b/build.gradle
index 6ae65325055..d246b49293a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -551,6 +551,41 @@ subprojects {
}
}
+ // Do not run this task with Java 8. It will use an older version of Mockito,
+ // which depends on an older Byte Buddy version that does not support Java
25.
+ task testWithJava25(type: Test, dependsOn: compileJava) {
+ description = 'Run tests using Java 25 toolchain'
+
+ javaLauncher = javaToolchains.launcherFor {
+ languageVersion = JavaLanguageVersion.of(25)
+ }
+
+ maxParallelForks = maxTestForks
+ ignoreFailures = userIgnoreFailures
+ maxHeapSize = defaultMaxHeapSize
+ jvmArgs = defaultJvmArgs
+
+ testLogging {
+ events = userTestLoggingEvents ?: testLoggingEvents
+ showStandardStreams = userShowStandardStreams ?: testShowStandardStreams
+ exceptionFormat = testExceptionFormat
+ displayGranularity = 0
+ }
+
+ logTestStdout.rehydrate(delegate, owner, this)()
+
+ exclude testsToExclude
+
+ useJUnitPlatform {
+ includeEngines 'junit-jupiter'
+ }
+
+ retry {
+ maxRetries = userMaxTestRetries
+ maxFailures = userMaxTestRetryFailures
+ }
+ }
+
// remove test output from all test types
tasks.withType(Test).all { t ->
cleanTest {
diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle
index f659099a587..627a6c6d26e 100644
--- a/gradle/dependencies.gradle
+++ b/gradle/dependencies.gradle
@@ -61,7 +61,7 @@ String mockitoVersion
if (scalaVersion == "2.12")
mockitoVersion = "4.9.0"
else if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11))
- mockitoVersion = "5.14.2"
+ mockitoVersion = "5.20.0"
else
mockitoVersion = "4.11.0"
diff --git a/settings.gradle b/settings.gradle
index 92df42212dd..6dd5509428c 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -16,6 +16,8 @@
plugins {
id 'com.gradle.enterprise' version '3.14.1'
id 'com.gradle.common-custom-user-data-gradle-plugin' version '1.11.1'
+ // Using 0.10.0 for JDK 8 compatibility (1.0.0 requires JDK 17)
+ id 'org.gradle.toolchains.foojay-resolver-convention' version '0.10.0'
}
def isGithubActions = System.getenv('GITHUB_ACTIONS') != null