Releases: sbt/sbt-java-formatter
0.12.0
sbt-java-formatter 0.12.0 is cross-published for:
| sbt Version | Published |
|---|---|
| 1.x | ✅ |
| 2.x | ✅ |
Highlights
This release changes how sbt-java-formatter runs google-java-format on modern JDKs.
Instead of calling the formatter library directly inside the sbt JVM, the plugin now launches the released google-java-format CLI in a dedicated forked JVM and passes the required jdk.compiler access flags there automatically. This makes formatter execution work consistently regardless of how formatting is triggered, and removes the need for wrapper-based --add-exports workarounds.
Migration
- You can remove any formatter-related
--add-exportsflags, since the plugin now manages the required formatter JVM module access flags itself. - If you run sbt on Java 21 or newer, there is nothing to do. Everything works out of the box. 🪄
- If you run sbt on Java 11 or Java 17, you have two choices:
- If you want to use the latest
google-java-formatversion, you need to run the formatter on Java 21 or newer. That means sbt itself can keep running on one JDK while formatting runs on another. SetSBT_JAVAFMT_JAVA_HOMEor-Dsbt-javafmt.java.home=...to point the formatter to a different JDK. - If you do not care about using the latest
google-java-formatversion and do not want to set up a second Java installation on your machine or CI, setThisBuild / javafmtFormatterCompatibleJavaVersion := 11or:= 17explicitly. This will use the newest formatter release compatible with that Java version instead of the latest overall release:1.24.0for Java 11 and1.28.0for Java 17. Be aware that even if you upgradesbt-java-formatterlater,google-java-formatwill remain on the compatibility line selected here until you change the setting again.
- If you want to use the latest
Note
Many projects use Java 17 as their baseline today. If that is true for your build, ThisBuild / javafmtFormatterCompatibleJavaVersion := 17 is often the simplest setup.
The main Java language support changes in google-java-format after v1.28.0 are:
- Initial support for import module in google-java-format
- Support Instance Main Methods in google-java-format
If you do not use these language features, setting ThisBuild / javafmtFormatterCompatibleJavaVersion := 17 lets sbt-java-formatter work out of the box on CI servers and developer machines that run sbt on Java 17.
- Prefer the dedicated
javafmt...sbt settings overjavafmtOptions.javafmtOptionsstill exists for compatibility, but it is no longer the main configuration surface. reorderModifiers(false)is still not supported through the current CLI-backed execution path, because the releasedgoogle-java-formatCLI does not yet expose a corresponding skip flag (see #266 and google/google-java-format#1373).- To set the
SBT_JAVAFMT_JAVA_HOMEenvironment variable in GitHub Actions workflows, you can use the following snippet. Insert it before the first step that runs ansbtcommand which may trigger the formatter:- name: Set Java installation used by sbt-java-formatter to run google-java-format shell: bash run: | # JAVA_HOME_25_X64 is available on GitHub-hosted Ubuntu (+ ARM) and Windows images; the fallbacks cover macOS. formatter_java_home="${JAVA_HOME_25_X64:-${JAVA_HOME_25_arm64:-$JAVA_HOME_25_aarch64}}" [ -n "$formatter_java_home" ] || { echo "None of JAVA_HOME_25_X64, JAVA_HOME_25_arm64, or JAVA_HOME_25_aarch64 is set" exit 1 } [ -x "$formatter_java_home/bin/java" ] || { echo "No executable java found at $formatter_java_home/bin/java" exit 1 } echo "SBT_JAVAFMT_JAVA_HOME=$formatter_java_home" >> "$GITHUB_ENV"
- Examples of this snippet can be found in a reusable Play Framework workflow here.
New
SBT_JAVAFMT_JAVA_HOMEand-Dsbt-javafmt.java.home=...let the formatter JVM use a different JDK than the sbt JVM.javafmtFormatterCompatibleJavaVersionselects the compatible formatter runtime line:11->google-java-format 1.24.017->google-java-format 1.28.021->google-java-format 1.35.0(default; latest at the time of this release)
- Dedicated import-only tasks are now available:
javafmtFixImportsjavafmtFixImportsAlljavafmtFixImportsCheckjavafmtFixImportsCheckAll
- More formatter CLI behavior is now exposed through first-class sbt settings:
javafmtSortImportsjavafmtRemoveUnusedImportsjavafmtReflowLongStringsjavafmtFormatJavadocjavafmtJavaMaxHeap
Examples
- Typical modern setup: sbt runs on a pre-Java 21 installation, but you still want to use the latest
google-java-format:SBT_JAVAFMT_JAVA_HOME=/path/to/jdk-[21|25] sbt javafmtCheckAll - sbt runs on Java 11 or 17, and you do not want to (or can not) install a second Java 21+ runtime:
// sbt runs on Java 11 (this keeps google-java-format on version 1.24.0) ThisBuild / javafmtFormatterCompatibleJavaVersion := 11 // sbt runs on Java 17 (this keeps google-java-format on version 1.28.0) ThisBuild / javafmtFormatterCompatibleJavaVersion := 17
What's Changed
- bump: scala3-library 3.8.3 (was 3.8.2) by @scala-steward in #254
- sbt 2.0.0-RC11 by @xuwei-k in #257
- bump: scalafmt-core 3.10.7 (was 3.9.10) by @scala-steward in #256
- bump: sbt, scripted-plugin 1.12.9 (was 1.11.7) by @scala-steward in #255
- bump: sbt-scalafmt 2.5.6 (was 2.5.4) by @scala-steward in #249
- bump: scala-library 2.12.21 (was 2.12.18) by @scala-steward in #246
- build(deps): bump actions/checkout from 5 to 6 by @dependabot[bot] in #245
--add-exportsinstead of--add-opensas stated in the google-java-formatter docs by @mkurz in #258- Add
sbt-java-formatter-add-opensplugin by @mkurz in #261 - Add scalafmtCheckAll in CI by @xuwei-k in #262
- Switch formatter to forked google-java-format CLI in dedicated JVM by @mkurz in #264
--add-exportsnot needed anymore inscriptedLaunchOptsby @mkurz in #265- Add settings for import handling and long string reflow by @mkurz in #267
- Add
javafmtFixImportstasks for import-only mode by @mkurz in #268 - Add
javafmtFormatJavadocsetting by @mkurz in #269 - Restore reorderModifiers guard for the forked formatter CLI by @mkurz in #270
- Support overriding the formatter Java home by @mkurz in #271
- Select formatter runtimes explicitly and add Java compatibility coverage by @mkurz in #272
- Use a Scala Steward hook to update the runtime google-java-format mapping by @mkurz in #273
- bump: sbt-scalafmt 2.6.0 (was 2.5.6) by @mkurz in #275
- bump: scalafmt-core 3.11.0 (was 3.10.7) by @mkurz in #276
- Downgrade google-java-format to test scala steward hook by @mkurz in #277
- we want scala steward update asap by @mkurz in #278
- bump: google-java-format 1.35.0 (was 1.24.0) by @mkurz in #279
- update README by @mkurz in #280
- fix readme by @mkurz in #281
- Log Java runtime mismatch hints once per project (instead of once globally) by @mkurz in #282
- Deduplicate Java runtime mismatch hints per formatter invocation by @mkurz in #283
- Add url to info text by @mkurz in #284
- Add note about
javafmtFormatterCompatibleJavaVersion := 17by @mkurz in #287
Full Changelog: v0.11.0...v0.12.0
0.12.0-RC1
sbt-java-formatter 0.12.0-RC1 is cross-published for:
| sbt Version | Published |
|---|---|
| 1.x | ✅ |
| 2.x | ✅ |
See final 0.12.0 release: https://github.com/sbt/sbt-java-formatter/releases/tag/v0.12.0
0.11.0
sbt-java-formatter 0.11.0 is cross published to:
| sbt Version | Published |
|---|---|
| 1.x | ✅ |
| 2.x | ✅ |
sbt 2.x migration
behind the scenes
- ci: Latest sbt and sbt-ci-release by @mkurz in #227
- ci: Publish snapshots by @mkurz in #228
- ci: Fix versioning on CI by @mkurz in #229
- ci: Add dependabot.yml for GitHub Actions update by @xuwei-k in #236
- ci: Bump actions/checkout from 4 to 5 by @dependabot[bot] in #237
- ci: Bump actions/setup-java from 4 to 5 by @dependabot[bot] in #238
- ci: Bump: sbt, scripted-plugin 1.11.7 (was 1.11.5) by @scala-steward in #243
- ci: Bump: scalafmt-core 3.9.10 (was 3.9.4) by @scala-steward in #244
- ci: Bump: sbt-ci-release 1.11.2 (was 1.11.1) by @scala-steward in #240
- ci: Bump: sbt-header 5.11.0 (was 5.10.0) by @scala-steward in #241
new contributors
- @dependabot[bot] made their first contribution in #237
Full Changelog: v0.10.0...v0.11.0
0.10.0
Breaking changes
- Drop support for Java 8, requires Java 11 now.
- Google's
google-java-formatwas upgraded from version 1.7 to 1.24.0
If you still need support for Java 8 you can keep using version 0.9.0.
Noteworthy
With the previous 0.9.0 release the groupId changed from com.lightbend.sbt to com.github.sbt:
// new:
addSbtPlugin("com.github.sbt" % "sbt-java-formatter" % ---version---) // starting with v0.9.0
// old:
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % ---version---) // until v0.8.0The package com.lightbend.sbt was renamed to com.github.sbt as well.
What's Changed
- Upgrade google formatter to v1.24.0 - the last version supporting Java 11 by @mkurz in #218
- Remove setup scala by @mkurz in #222
Full Changelog: v0.9.0...v0.10.0
0.9.0
Breaking changes
The groupId changed from com.lightbend.sbt to com.github.sbt:
// new:
addSbtPlugin("com.github.sbt" % "sbt-java-formatter" % ---version---) // starting with v0.9.0
// old:
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % ---version---) // until v0.8.0The package com.lightbend.sbt was renamed to com.github.sbt as well.
What's Changed
- chore: calm down Scala Steward by @ennru in #195
- bump: sbt-pgp 2.3.0 (was 2.1.2) by @scala-steward in #215
- bump: sbt-ci-release 1.9.0 (was 1.5.10) by @scala-steward in #214
- bump: sbt-dynver 5.1.0 (was 4.1.1) by @scala-steward in #213
- bump: scalafmt-core 3.8.3 (was 2.7.5) by @scala-steward in #211
- bump: sbt-header 5.10.0 (was 5.7.0) by @scala-steward in #205
- bump: sbt-scalafmt 2.5.2 (was 2.4.6) by @scala-steward in #207
- bump: sbt, scripted-plugin 1.7.3 (was 1.7.2) by @scala-steward in #199
- fix warning in build.sbt by @xuwei-k in #212
- Update all dependencies + scalafmt by @mkurz in #217
- Move to com.github.sbt organization + cross build to sbt 2.x by @eed3si9n in #219
- Fix formatting by @mkurz in #220
- Remove
publishTo, we use sbt-ci-release by @mkurz in #221
Full Changelog: v0.8.0...v0.9.0
0.8.0
What's Changed
- Use the Import Sorting Feature of the Formatter by @tamas4sunairio in #190
"Fixing imports includes ordering, spacing, and removal of unused import statements."
Chore
- gh actions setup used plugin not included in build by @johanandren in #157
- bump: sbt, scripted-plugin 1.5.6 (was 1.5.5) by @scala-steward in #165
- bump: sbt-ci-release 1.5.10 (was 1.5.9) by @scala-steward in #161
- bump: sbt, scripted-plugin 1.5.7 (was 1.5.6) by @scala-steward in #166
- bump: sbt, scripted-plugin 1.5.8 (was 1.5.7) by @scala-steward in #167
- bump: sbt, scripted-plugin 1.7.1 (was 1.5.8) by @scala-steward in #188
- bump: sbt-header 5.6.5 (was 5.6.0) by @scala-steward in #180
- bump: sbt-scalafmt 2.4.6 (was 2.4.3) by @scala-steward in #169
- bump: sbt, scripted-plugin 1.7.2 (was 1.7.1) by @scala-steward in #192
- bump: sbt-header 5.7.0 (was 5.6.5) by @scala-steward in #191
New Contributors
- @johanandren made their first contribution in #157
- @tamas4sunairio made their first contribution in #190
https://github.com/sbt/sbt-java-formatter/milestone/14?closed=1
Full Changelog: v0.7.0...v0.8.0
0.7.0
This release switches the default of format on compile to false, making it opt in.
0.6.1
0.6.0 - support AOSP style
Formatter can be configured to use either Google Java Style (by default) or AOSP style.
Allow any other java formatter options to be configured, such as enabling or disabling Javadoc formatting.
Changes
- Add settings allowing AOSP style (#100) by @joriscode