Skip to content

Releases: sbt/sbt-java-formatter

0.12.0

21 Apr 12:47
v0.12.0
6baceea

Choose a tag to compare

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-exports flags, 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-format version, 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. Set SBT_JAVAFMT_JAVA_HOME or -Dsbt-javafmt.java.home=... to point the formatter to a different JDK.
    • If you do not care about using the latest google-java-format version and do not want to set up a second Java installation on your machine or CI, set ThisBuild / javafmtFormatterCompatibleJavaVersion := 11 or := 17 explicitly. This will use the newest formatter release compatible with that Java version instead of the latest overall release: 1.24.0 for Java 11 and 1.28.0 for Java 17. Be aware that even if you upgrade sbt-java-formatter later, google-java-format will remain on the compatibility line selected here until you change the setting again.

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:

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 over javafmtOptions. javafmtOptions still 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 released google-java-format CLI does not yet expose a corresponding skip flag (see #266 and google/google-java-format#1373).
  • To set the SBT_JAVAFMT_JAVA_HOME environment variable in GitHub Actions workflows, you can use the following snippet. Insert it before the first step that runs an sbt command 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_HOME and -Dsbt-javafmt.java.home=... let the formatter JVM use a different JDK than the sbt JVM.
  • javafmtFormatterCompatibleJavaVersion selects the compatible formatter runtime line:
    • 11 -> google-java-format 1.24.0
    • 17 -> google-java-format 1.28.0
    • 21 -> google-java-format 1.35.0 (default; latest at the time of this release)
  • Dedicated import-only tasks are now available:
    • javafmtFixImports
    • javafmtFixImportsAll
    • javafmtFixImportsCheck
    • javafmtFixImportsCheckAll
  • More formatter CLI behavior is now exposed through first-class sbt settings:
    • javafmtSortImports
    • javafmtRemoveUnusedImports
    • javafmtReflowLongStrings
    • javafmtFormatJavadoc
    • javafmtJavaMaxHeap

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-exports instead of --add-opens as stated in the google-java-formatter docs by @mkurz in #258
  • Add sbt-java-formatter-add-opens plugin 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-exports not needed anymore in scriptedLaunchOpts by @mkurz in #265
  • Add settings for import handling and long string reflow by @mkurz in #267
  • Add javafmtFixImports tasks for import-only mode by @mkurz in #268
  • Add javafmtFormatJavadoc setting 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 := 17 by @mkurz in #287

Full Changelog: v0.11.0...v0.12.0

0.12.0-RC1

17 Apr 10:25
v0.12.0-RC1
3f61339

Choose a tag to compare

0.12.0-RC1 Pre-release
Pre-release

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

02 Apr 02:13
v0.11.0
9b14e8d

Choose a tag to compare

sbt-java-formatter 0.11.0 is cross published to:

sbt Version Published
1.x
2.x

sbt 2.x migration

behind the scenes

new contributors

Full Changelog: v0.10.0...v0.11.0

0.10.0

22 Apr 18:55
v0.10.0
01c87a7

Choose a tag to compare

Breaking changes

  • Drop support for Java 8, requires Java 11 now.
  • Google's google-java-format was 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.0

The 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

22 Apr 18:50
v0.9.0
531e616

Choose a tag to compare

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.0

The package com.lightbend.sbt was renamed to com.github.sbt as well.

What's Changed

Full Changelog: v0.8.0...v0.9.0

0.8.0

20 Oct 15:46
839a326

Choose a tag to compare

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

New Contributors

https://github.com/sbt/sbt-java-formatter/milestone/14?closed=1

Full Changelog: v0.7.0...v0.8.0

0.7.0

17 Nov 10:40
1fc9fcc

Choose a tag to compare

This release switches the default of format on compile to false, making it opt in.

See #151 Set javafmtOnCompile := false by default

0.6.1

25 Aug 13:42

Choose a tag to compare

Changes

  • Re-release on Maven Central, migrating off of Bintray. #126 / #130

Milestone: https://github.com/sbt/sbt-java-formatter/milestone/11

0.6.0 - support AOSP style

17 Aug 03:20
256b9a1

Choose a tag to compare

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 `javafmtOnCompile` setting

06 Mar 11:36
9dc94ef

Choose a tag to compare

Introduces the setting javafmtOnCompile so that users can op-out of Java formatting triggered by compilation.