Skip to content

Add configurable line length and configuration-aware caching - #315

Merged
mkurz merged 1 commit into
sbt:mainfrom
mkurz:support-formatter-1.37-cli-and-cache
Oct 1, 2026
Merged

mkurz merged 1 commit into
sbt:mainfrom
mkurz:support-formatter-1.37-cli-and-cache

Conversation

@mkurz

@mkurz mkurz commented Oct 1, 2026

Copy link
Copy Markdown
Member

Summary

Upgrade the Java 21-compatible formatter runtime to google-java-format 1.37.0 and expose its configurable line length. The Java 11 and Java 17 compatibility lines remain on 1.24.0 and 1.28.0.

  • Add javafmtMaxLineLength, defaulting to 100, and map custom values to --max-line-length. Values must be positive; custom widths require javafmtFormatterCompatibleJavaVersion := 21.
  • Document how the existing javafmtStyle setting covers the new --style=google|aosp and --google-style aliases without introducing duplicate settings.
ThisBuild / javafmtMaxLineLength := 120

Cache Fixes

The previous cache tracked source timestamps only, so changing formatter options could leave unchanged files unchecked or unformatted. Import-only checks also shared cache state with full-formatting tasks, allowing an imports-only result to incorrectly satisfy a full-format check.

  • Invalidate caches when the effective CLI options, formatter classpath, heap setting, or resolved Java home change. Java-home symlink retargeting is detected immediately, including on Java 11.
  • Separate import-only and full-formatting caches while retaining cache sharing between formatting and checking within each mode.
  • Ignore full-formatting options and their compatibility checks for import-only tasks. Only style, import sorting, and unused-import removal affect their output; unrelated option changes do not invalidate their cache.
  • Keep Java-launcher validation deferred until a formatter process is needed, so Scala-only modules still work with a missing or malformed formatter Java home.

Shared formatter arguments remain mandatory, preventing future full-formatting callers from silently dropping configured line-length or string-reflow settings.

Verification

Added scripted coverage for option changes on unchanged sources, cache-mode isolation, import-only options, line lengths and string wrapping, runtime changes, symlink retargeting and recovery, no-source builds, and compatibility validation. The new runtime tests are included in CI.

All 64 scripted runs passed across the five Java/sbt combinations: sbt 1 on Java 11; sbt 2 on Java 17, 21, and 25; and sbt 1 on Java 11 with the formatter on Java 25. After the final explicit-argument cleanup, all 15 targeted reruns passed on sbt 1/Java 11 and sbt 2/Java 21. Formatting checks also passed.

Select formatter 1.37.0 for Java 21-compatible execution and expose javafmtMaxLineLength with compatibility validation and documentation.

Invalidate caches when the effective invocation changes, including CLI options, formatter classpath, heap settings, and resolved Java-home targets. Separate import-only and full-format caches, ignore irrelevant formatting options for import-only tasks, and defer launcher validation until execution.

Keep shared formatter arguments mandatory so full-format callers cannot silently ignore user settings. Add scripted coverage for line lengths, configuration and runtime changes, symlink retargeting, no-source builds, import-only isolation, and version guards across sbt 1 and 2.
@mkurz mkurz changed the title Support google-java-format 1.37.0 and configuration-aware caching Add configurable line length and configuration-aware caching Oct 1, 2026

@eed3si9n eed3si9n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mkurz
mkurz merged commit ad2eed2 into sbt:main Oct 1, 2026
5 checks passed
@mkurz
mkurz deleted the support-formatter-1.37-cli-and-cache branch October 1, 2026 19:37
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