Skip to content

Support overriding the formatter Java home#271

Merged
mkurz merged 1 commit into
sbt:mainfrom
mkurz:javafmt-java-home-overrides
Apr 15, 2026
Merged

Support overriding the formatter Java home#271
mkurz merged 1 commit into
sbt:mainfrom
mkurz:javafmt-java-home-overrides

Conversation

@mkurz
Copy link
Copy Markdown
Member

@mkurz mkurz commented Apr 15, 2026

Adds explicit Java home overrides for the forked google-java-format JVM.

The plugin currently falls back to the same Java installation used by the sbt process via java.home. This works well by default, but on CI servers or developer machines it can be useful to run the formatter with a different JDK without changing the JDK that sbt itself runs on.

This change adds two override mechanisms:

  1. JVM system property: sbt-javafmt.java.home
  2. Environment variable: SBT_JAVAFMT_JAVA_HOME

Resolution order is now:

  1. sbt-javafmt.java.home
  2. SBT_JAVAFMT_JAVA_HOME
  3. java.home

So users can now do either of these:

sbt -Dsbt-javafmt.java.home=/path/to/jdk javafmt

SBT_JAVAFMT_JAVA_HOME=/path/to/jdk sbt javafmt

The plugin still defaults to sbt's own java.home when neither override is set.

@mkurz mkurz force-pushed the javafmt-java-home-overrides branch from b137422 to ccaaaff Compare April 15, 2026 16:56
@mkurz mkurz merged commit f98dd76 into sbt:main Apr 15, 2026
2 checks passed
@mkurz mkurz mentioned this pull request Apr 15, 2026
@mkurz mkurz deleted the javafmt-java-home-overrides branch April 15, 2026 17:04
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