Skip to content

Fix spotless:apply failure on modern JDKs#777

Merged
Divyansh-db merged 1 commit intomainfrom
test-generation
Apr 23, 2026
Merged

Fix spotless:apply failure on modern JDKs#777
Divyansh-db merged 1 commit intomainfrom
test-generation

Conversation

@Divyansh-db
Copy link
Copy Markdown
Contributor

@Divyansh-db Divyansh-db commented Apr 23, 2026

Summary

  • Pin google-java-format to 1.22.0 in the root pom.xml so mvn spotless:apply stops crashing on modern JDKs
    (the code generator runs on JDK 25, where spotless-maven-plugin 2.30.0's bundled GJF 1.15.0 throws
    NoSuchMethodError against the renamed com.sun.tools.javac.util.Log$DeferredDiagnosticHandler.getDiagnostics()
    signature). 1.22.0 is the last GJF release that still supports JRE 11, keeping local dev and the JDK 11 fmt CI job
    working.
  • Add scripts/mvn-spotless-apply.sh, a drop-in wrapper that exports MAVEN_OPTS with the
    --add-exports=jdk.compiler/com.sun.tools.javac.*=ALL-UNNAMED flags required by GJF on JDK 16+. It detects the JDK
    major version and only sets the flags when needed, so older JDKs (including the JDK 8 CI matrix rows) are untouched.
    .codegen.json's post_generate now invokes the wrapper instead of mvn spotless:apply directly, mirroring the
    existing bash scripts/cleanup-services.sh pattern.
  • One-time reformat of 6 files (16 blank lines inserted, 0 deletions) to satisfy GJF 1.22.0's stricter rules around
    blank lines between documented fields. No semantic changes.

Why a wrapper script and not .mvn/jvm.config?

.mvn/jvm.config applies to every Maven invocation, and this repo's CI matrix runs mvn test / release jobs under
JDK 8, where --add-exports is an unrecognized arg and Maven would fail to start. Scoping the flags to the one
command that actually needs them (spotless:apply) avoids that blast radius.

Impact on CI

  • fmt (JDK 11 → spotless:check): GJF 1.22.0 loads fine on JRE 11.
  • unit-tests matrix (JDK 8/11/17/20 → mvn test): unaffected, spotless plugin has no <execution> binding so it
    never runs during tests.
  • release-build-check / package (JDK 8): unaffected, same reason.
  • Compiled bytecode target remains Java 8; GJF only reformats source whitespace.

Test plan

  • mvn spotless:check passes on local JDK 11 after the reformat
  • mvn spotless:apply on clean HEAD (after pom bump) produces the expected 6-file reformat only; subsequent runs
    are no-ops (idempotent)
  • bash scripts/mvn-spotless-apply.sh on JDK 11 correctly skips the MAVEN_OPTS export (JDK < 16) and
    delegates to mvn spotless:apply with BUILD SUCCESS
  • CI green across all matrix rows (JDK 8/11/17/20 unit-tests, JDK 11 fmt, JDK 8 release-build-check)

NO_CHANGELOG=true

Pin google-java-format to 1.22.0 explicitly so the code-generator's
post-generate step no longer crashes with NoSuchMethodError on JDK 25.
The spotless-maven-plugin 2.30.0 default GJF (1.15.0) calls a javac
internal (Log$DeferredDiagnosticHandler.getDiagnostics) whose signature
changed in JDK 21+. 1.22.0 is the last GJF release that still supports
JRE 11, keeping local dev and the JDK 11 fmt CI job working.

Add scripts/mvn-spotless-apply.sh as a drop-in wrapper that exports
--add-exports MAVEN_OPTS for jdk.compiler internals on JDK 16+, which
GJF needs to access javac's tokenizer/parser under the module system.
The wrapper detects the JDK version so older JDKs are untouched.
.codegen.json's post_generate step now invokes the wrapper.

One-time reformat of 6 files (16 blank lines added) under GJF 1.22.0's
stricter rules around documented fields; no semantic changes.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown
Contributor

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-java

Inputs:

  • PR number: 777
  • Commit SHA: b3daa40298ab78b6578dec06114948a12d6de193

Checks will be approved automatically on success.

@Divyansh-db Divyansh-db added this pull request to the merge queue Apr 23, 2026
Merged via the queue into main with commit f850f56 Apr 23, 2026
19 of 20 checks passed
@Divyansh-db Divyansh-db deleted the test-generation branch April 23, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants