Repository navigation
feat: check Java formatting with Spotless and google-java-format - #35
Merged
Merged
Conversation
Java formatting was only checked by the treefmt pre-commit hook, so commits made without Nix or with --no-verify could land unformatted, and CI never noticed. Spotless now runs google-java-format as part of ./gradlew build, so CI rejects unformatted Java and ./gradlew spotlessApply fixes it. treefmt no longer formats Java, which leaves Spotless as the only formatter. google-java-format is pinned to 1.36.1 because Spotless 8.10.3 fails on 1.37.0, where JavaFormatterOptions.Style became a record (diffplug/spotless#3126).
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.
Why
Java formatting was only checked by the treefmt pre-commit hook. Contributors without Nix, and commits made with
--no-verify, could land unformatted Java, and CI did not catch it.What
./gradlew build, and so CI, now runsspotlessCheck, and./gradlew spotlessApplyformats the sources.nix fmtformats only Nix.Trade-offs
NoSuchMethodError, becauseJavaFormatterOptions.Stylebecame a record (diffplug/spotless#3126, fix proposed in google/google-java-format#1472). Dependabot's bump to 1.37.0 will fail CI until one of them ships../gradlew buildor in CI. RunningspotlessCheckin the hook was rejected because it starts Gradle on every commit. Keeping google-java-format in both treefmt and Spotless was rejected because the two versions would drift apart as nixpkgs updates.build.gradle.ktsis still not formatted by any tool.Verification
Checked:
spotlessCheckwith 1.36.1 unchanged.FinalClass.javamakes./gradlew buildfail atspotlessJavaCheck, and./gradlew spotlessApplyrestores the original file.nix flake checkpasses, andnix fmtprocesses only Nix files.Not checked:
nix flake checkon aarch64-linux and x86_64-linux.