sbt / sbt-java-formatter

An sbt plugin for formating Java code


sbt-java-formatter scaladex-badge travis-badge

An sbt plugin for formatting Java code. This plugin began as a combination of ideas from this blog post and this maven plugin, though it has evolved since.


Add the plugin to project/plugins.sbt:

addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % --latest version---)

For available versions see releases.

  • javafmt formats Java files (done automatically on compile for Compile and Test configurations, unless javafmtOnCompile := false is set)

  • javafmtAll formats Java files for all configurations (Compile and Test by default)

  • javafmtCheck fails if files need reformatting

  • javafmtCheckAll fails if files need reformatting in any configuration (Compile and Test by default)

  • The javafmtOnCompile setting controls whether the formatter kicks in on compile (true by default as the AutomateJavaFormatterPlugin is triggered if not disabled explicitly).

This plugin requires sbt 1.3.0+.

Enable in other scopes (eg IntegrationTest)

The sbt plugin is enabled by default for the Test and Compile configurations. Use JavaFormatterPlugin.toBeScopedSettings to enable the plugin for the IntegrationTest scope and then use It/javafmt to format.



This plugin uses the Google Java Format library, which makes it quite opinionated and not particularly configurable.

If you want to tweak the format, take a minute to consider whether it is really worth it, and have a look at the motivations in the Google Java Style Guide. If you decide you really need more flexibility, you could consider other plugins such as the sbt-checkstyle-plugin


Yes, we'll happily accept PRs to improve the plugin. We expect you to adhere to the Lightbend Community Code of Conduct and to sign the Lightbend Contributor License Agreement - CLA.

Take a look at the contributors graph if you want to contact any of the contributors directly.


Apache v2