Add JDK 17 fallback to mvn-spotless-apply.sh#841
Merged
Conversation
scripts/mvn-spotless-apply.sh previously exec'd `mvn spotless:apply` directly, so when the default JDK was older than 17 (the minimum required by the pinned google-java-format 1.27.0) it failed with no recovery. Mirror the `make fmt` -> `make fmt-jdk17` fallback: try the selected JDK first, and if that fails retry under an explicit JDK 17 install, always applying the javac --add-exports flags GJF needs on JDK 16+. To keep the fallback honest and portable: - detect the JDK version from the JVM Maven actually uses ($JAVA_HOME/bin/java if JAVA_HOME is set, else `java` on PATH), so the add-exports gating matches the running JDK and re-running with JAVA_HOME=<jdk17> succeeds on the first attempt; - allow the fallback location to be overridden via JDK17_HOME for non-Debian layouts, and error clearly (pointing at JDK17_HOME / JAVA_HOME) when no JDK 17 is found.
Contributor
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
parthban-db
approved these changes
Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a JDK 17 fallback to
scripts/mvn-spotless-apply.shsomvn spotless:applystill formats successfully when the default JDK is older than 17, bringing the
script to parity with the existing
make fmt→make fmt-jdk17behaviour.Why
scripts/mvn-spotless-apply.shis the wrapper used to runspotless:apply(it isinvoked by codegen post-generation via
.codegen.json, and by contributors whoformat locally). It exported the
--add-exportsflags google-java-format needs onJDK 16+, then
exec'dmvn spotless:applydirectly — with no recovery path.The pinned google-java-format
1.27.0requires JRE 17+. So on a machine whosedefault JDK is older than 17 (e.g. JDK 11) the command fails outright with a
PluginContainerException, even when a JDK 17 is installed on the box.make fmtalready guards against this — it retries under JDK 17 (make fmt-jdk17)when the first
spotless:applyfails. The script had no such safety net. This PRadds the equivalent fallback so both entry points behave the same.
What changed
Interface changes
None to any public API — this is an internal build script. It is still invoked the
same way (
bash scripts/mvn-spotless-apply.sh); the only addition is an optionalJDK17_HOMEenvironment override.Behavioral changes
spotless:applyattempt fails, the script now prints a clear messageand retries once under an explicit JDK 17 install instead of exiting.
$JAVA_HOME/bin/javawhen
JAVA_HOMEis set, otherwisejavaonPATH. This makes the--add-exportsgating match the running JDK, and means re-running with
JAVA_HOMEpointed at aJDK 17+ succeeds on the first attempt (no fallback needed).
JDK17_HOME(defaulting to thesame Debian/amd64 path
make fmtuses), and the script errors clearly — pointingat
JDK17_HOME/JAVA_HOME— when no JDK 17 is found.Internal changes
NEXT_CHANGELOG.mdentry under Internal Changes.How is this tested?
Verified manually on a machine whose default JDK is 11 with JDK 17 installed:
bash scripts/mvn-spotless-apply.sh): the first attempt underJDK 11 fails as expected (
BUILD FAILURE), the fallback message is printed, and theJDK 17 retry runs
spotless:applytoBUILD SUCCESS(exit 0).JAVA_HOME=<jdk17> bash scripts/mvn-spotless-apply.sh: succeeds on the firstattempt with no fallback, confirming the version detection honours
JAVA_HOME.bash -nsyntax check passes.