A sbt plugin for checking Java code styles with checkstyle.
Add sbt-jcheckstyle plugin to your project/plugins.sbt
, then run jcheckStyle
task:
project/plugins.sbt
// For sbt-0.13.x and 1.0.x
addSbtPlugin("org.xerial.sbt" % "sbt-jcheckstyle" % "(version)")
# Check code style of java codes
$ sbt jcheckStyle
# Check code style of java test codes
$ sbt test:jcheckStyle
Add the following sbt settings:
compile in Compile <<= (compile in Compile) dependsOn (jcheckStyle in Compile)
compile in Test <<= (compile in Test) dependsOn (jcheckStyle in Test)
To configure Java code style, edit jcheckStyleConfig
setting. In default, it uses Google's Java style:
jcheckStyleConfig := "google" // or "facebook", "sun" or path to your checkstyle.xml
Here is the list of the available styles:
google
: Google's Java Style. checkstyle.xmlfacebook
: Code style used in Facebook Prestosun
: Code Conventions for the Java TM Programming Language. checkstyle.xml
Or you can specify your own configuration:
jcheckStyleConfig := "checkstyle.xml"