I've released sbt-spotless, this is an sbt plugin for Spotless.
addSbtPlugin("net.moznion.sbt" % "sbt-spotless" % "0.1.3")
next, configure your
build.sbt for code formatter(s):
import net.moznion.sbt.spotless.config._ lazy val root = (project in file(".")) .settings( name := "Example", spotlessJava := JavaConfig( googleJavaFormat = GoogleJavaFormatConfig("1.7") ), )
finally, you can run
sbt spotlessCheck and
sbt spotlessApply commands to check and apply the code formatter.
And – this feature is only available on sbt 1.3.x – you can use
applyOnCompile options like the following:
lazy val root = (project in file(".")) .settings( name := "Example", spotless := SpotlessConfig( checkOnCompile = true, // applyOnCompile = true, ), )
then, it checks or applies the code formatter automatically on compiling, automatically.
If you'd like to know configuration in detail, please refer to the following documentation: Configurations · moznion/sbt-spotless Wiki · GitHub
This plugin supports Java, Scala, Kotlin, Groovy, C++, and SQL formatters so far, but Spotless core supports various formatters furthermore. Please feel free to ask me through an issue or pull-request if you feel this should support another formatter.
*1:but on sbt 0.13.x, the features are limited