From 3f9424fa3a81f41fdd1c2f1423d1b6c193c82520 Mon Sep 17 00:00:00 2001 From: Niels Pardon Date: Wed, 10 Jun 2026 15:33:20 +0200 Subject: [PATCH] build: bump google-java-format to 1.28.0 for JDK 22+ compatibility Spotless' google-java-format 1.23.0 calls com.sun.tools.javac internals that changed after JDK 21, so `spotlessCheck` fails with NoSuchMethodError (cascading to a Guava NoClassDefFoundError) when the Gradle daemon runs on JDK 22+. CI and JDK 17 developers are unaffected, which is why this only reproduced for some contributors locally. - Bump the Java step's google-java-format 1.23.0 -> 1.28.0. 1.28.0 is the newest release that still runs on JDK 17 (1.29.0+ require JDK 21), matching the daemon/CI toolchain, so it works across JDK 17-25. It produces identical formatting (no reformatting needed). - Pin build-logic's kotlin-dsl compilation to a Java 17 toolchain so the generated precompiled-script-plugin classes load on the daemon regardless of its JDK. Previously they were emitted as JDK 21 bytecode that a JDK 17 daemon could not load (UnsupportedClassVersionError). - Size build-logic's Kotlin compile daemon heap. build-logic is an included build and does not inherit the root gradle.properties, so a cold compile otherwise OOMs. --- build-logic/build.gradle.kts | 6 ++++++ build-logic/gradle.properties | 5 +++++ build.gradle.kts | 10 +++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 build-logic/gradle.properties diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index c390a1741..10a3b61bb 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -5,4 +5,10 @@ plugins { repositories { gradlePluginPortal() } +// Pin the precompiled-script-plugin compilation to Java 17 so the generated plugin classes load on +// the daemon regardless of which JDK it runs on. Without this, kotlin-dsl targets whatever JDK the +// daemon happens to use (e.g. 21/25), emitting newer bytecode that a Java 17 daemon cannot load +// (UnsupportedClassVersionError). +kotlin { jvmToolchain(17) } + spotless { kotlinGradle { ktfmt().googleStyle() } } diff --git a/build-logic/gradle.properties b/build-logic/gradle.properties new file mode 100644 index 000000000..5a91892ce --- /dev/null +++ b/build-logic/gradle.properties @@ -0,0 +1,5 @@ +# build-logic is an included build, so it does NOT inherit the root gradle.properties; its Kotlin +# compile daemon (which builds the precompiled script plugins) must be sized here. Without this the +# cold compile fails with an OOM / "internal compiler error" and falls back to a slow no-daemon +# compile. Raise -Xmx further if you still see those failures on a cold build. +kotlin.daemon.jvmargs=-Xmx2g diff --git a/build.gradle.kts b/build.gradle.kts index 09c233805..26b9fa396 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -62,9 +62,13 @@ allprojects { kotlinGradle { ktfmt("0.61").googleStyle() } java { target("src/*/java/**/*.java") - // since kfmt also brings in google-java-format we need to sync versions - // https://github.com/facebook/ktfmt/blob/v0.61/gradle/libs.versions.toml#L7 - googleJavaFormat("1.23.0") + // google-java-format 1.28.0: earlier versions (e.g. 1.23.0, which ktfmt 0.61 bundles) call + // com.sun.tools.javac internals that changed in recent JDKs, so Spotless throws + // NoSuchMethodError/NoClassDefFoundError when the daemon runs on a newer JDK (e.g. 25). + // 1.28.0 is the newest release that still runs on JDK 17 (1.29.0+ requires JDK 21+), + // matching the daemon/CI toolchain. This Java step has its own formatter classpath, + // independent of ktfmt's bundled copy (used only for Kotlin), so they need not match. + googleJavaFormat("1.28.0") removeUnusedImports() trimTrailingWhitespace() forbidWildcardImports()