Skip to content

Use a Scala Steward hook to update the runtime google-java-format mapping#273

Merged
mkurz merged 1 commit intosbt:mainfrom
mkurz:scala-steward-google-java-format-runtime-hook
Apr 16, 2026
Merged

Use a Scala Steward hook to update the runtime google-java-format mapping#273
mkurz merged 1 commit intosbt:mainfrom
mkurz:scala-steward-google-java-format-runtime-hook

Conversation

@mkurz
Copy link
Copy Markdown
Member

@mkurz mkurz commented Apr 16, 2026

Summary

This changes how Scala Steward should handle google-java-format updates in this repository.

We intentionally keep the compile-time dependency in build.sbt on 1.24.0, because the plugin is compiled against the Java 11-compatible API line. However, the runtime formatter selection is tracked separately through:

  • formatterVersionForCompatibleJavaVersion in JavaFormatterPlugin.scala
  • the compatibility table in README.md

Scala Steward cannot express that policy directly by itself. If we just unpin the dependency, it would normally only update the version in build.sbt, which is not what we want.

What this does

This PR removes the Scala Steward pin for google-java-format and adds a postUpdateHook for that dependency.

When Scala Steward bumps the version in build.sbt, the hook script now:

  1. reads the bumped google-java-format version from build.sbt
  2. restores the compile-time dependency in build.sbt back to 1.24.0
  3. updates the Java 21 runtime mapping in JavaFormatterPlugin.scala
  4. updates the corresponding Java 21 entry in README.md

So Scala Steward still uses the normal dependency update mechanism as the trigger, but the final diff is redirected to the files that actually represent the runtime formatter policy.

Why this is needed

The project currently has two different concerns:

  • compile the plugin against a stable Java 11-compatible formatter API line
  • let the forked formatter runtime track newer google-java-format releases for newer JDKs

Scala Steward understands dependency versions in build files, but not this repository-specific split between compile-time and runtime formatter versions. The hook makes that policy explicit.

Note

The hook includes a comment documenting the current assumption behind this automation:

  • the latest google-java-format release continues to belong to the Java 21 compatibility bucket

If upstream raises the runtime requirement again in the future, the hook and compatibility policy will need to be adjusted.

@mkurz mkurz merged commit 8a6e4db into sbt:main Apr 16, 2026
5 checks passed
@mkurz mkurz deleted the scala-steward-google-java-format-runtime-hook branch April 16, 2026 10:54
@mkurz
Copy link
Copy Markdown
Member Author

mkurz commented Apr 16, 2026

Seems to work when scala steward runs and wants to update to latest version that is already set in the mapping it skips to create a PR because nothing changed:

...
2026-04-16 12:55:43,678 INFO  Process update com.google.googlejavaformat:google-java-format : 1.24.0 -> 1.35.0
2026-04-16 12:55:44,115 INFO  Create branch update/google-java-format-1.35.0
2026-04-16 12:55:45,771 INFO  Executing post-update hook for com.google.googlejavaformat:google-java-format with command 'bash scripts/update-google-java-format-runtime.sh'
2026-04-16 12:55:45,894 WARN  No diff between base and update branch
...

@mkurz
Copy link
Copy Markdown
Member Author

mkurz commented Apr 16, 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