#sbt-java-formatter
An sbt plugin for formating Java code. Ideas from this blog post and this maven plugin.
- Add the plugin to
project/plugins.sbt
:
addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % JavaFormatterVersion)
-
Prepare a
formatting-java.xml
using Eclipse or steal someone's settings. -
Profit!
There is one optional step, in case you want to name the file differently, in which case you can do so via:
javaFormattingSettingsFilename := "my-little-formatting-settings.xml"
The plugin runs under the assumption that in multi-module projects, the "deeper" projects may want to specialize their formatting. In other words, the plugin looks up the config file using the folowing order:
1. my-example/project/formatting-java.xml
2. my-example/formatting-java.xml
3. project/formatting-java.xml
4. formatting-java.xml
Always defaulting at the "root" project's project/formatting-java.xml
(and lastly to formatting-java.xml
).
Yes, we'll happily accept PRs to improve the plugin. Please note that your changes should not accidentally cause reformatting of entire codebases (i.e. by changing defaults etc).
Please note that the plugin is very rough around the edges. It, in its current form was good enough for its initial use case, and we decided to share it instead of keeping it to ourselfes.
@bantonsson and/or @ktoso, at @lightbend
Apache v2