Skip to content

feat: check Java formatting with Spotless and google-java-format - #35

Merged
yagipass merged 1 commit into
mainfrom
feat/check-formatting-with-spotless
Oct 8, 2026
Merged

yagipass merged 1 commit into
mainfrom
feat/check-formatting-with-spotless

Conversation

@yagipass

@yagipass yagipass commented Oct 8, 2026

Copy link
Copy Markdown
Owner

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

  • Apply Spotless with google-java-format. ./gradlew build, and so CI, now runs spotlessCheck, and ./gradlew spotlessApply formats the sources.
  • Remove google-java-format from treefmt, so Spotless is the only Java formatter and nix fmt formats only Nix.
  • Update CONTRIBUTING.md to match.

Trade-offs

  • google-java-format is pinned to 1.36.1. Spotless 8.10.3 fails on 1.37.0 with NoSuchMethodError, because JavaFormatterOptions.Style became 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.
  • The pre-commit hook no longer checks Java formatting, so violations surface at ./gradlew build or in CI. Running spotlessCheck in 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.kts is still not formatted by any tool.

Verification

Checked:

  • The existing sources, formatted with 1.37.0 by treefmt, pass spotlessCheck with 1.36.1 unchanged.
  • Misformatting FinalClass.java makes ./gradlew build fail at spotlessJavaCheck, and ./gradlew spotlessApply restores the original file.
  • nix flake check passes, and nix fmt processes only Nix files.

Not checked:

  • nix flake check on aarch64-linux and x86_64-linux.

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).
@yagipass
yagipass merged commit 89d6a07 into main Oct 8, 2026
5 checks passed
@yagipass
yagipass deleted the feat/check-formatting-with-spotless branch October 8, 2026 03:45
@github-actions github-actions Bot mentioned this pull request Oct 6, 2026
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.

1 participant