keypoint
keypoint

Reputation: 2318

make sbt build fail on scalastyle warnings

I'm enforcing scalastyle check to my code space, referring http://www.scalastyle.org/sbt.html.

in build.sbt:

// scalastyle check
lazy val compileScalastyle = taskKey[Unit]("compileScalastyle")
compileScalastyle := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value
(compile in Compile) <<= (compile in Compile) dependsOn compileScalastyle

in project/plugins.sbt:

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")

When I run sbt compile, scalastyle is generating [warning] ***./utils/ConfigManager.scala: File must end with newline character, but compile still succeeded.

Is there a way to make sbt compile fail on scalastyle warnings?

I just change all <check level="warning" ...> to be <check level="error" ...> in scalastyleGenerateConfig, I'm not sure this is the right way to do it.

Thanks a lot

Upvotes: 3

Views: 2815

Answers (2)

vit fiala
vit fiala

Reputation: 78

The sbt plugin also has 2 relevant configurations mentioned in docs:

  1. scalastyleFailOnWarning which has default value false
  2. scalastyleFailOnError which has default true (docs says false but code says true)

Upvotes: 1

Michael Zajac
Michael Zajac

Reputation: 55569

There are really only two simple options that I can think of.

The obvious one is to change your scalastyle config so that the warnings you want to cause build failure are errors. That's really what the scalastyle config is for. If you want something to be treated as an error, call it one! <check level="error" ...> will give you the least amount of headache.

Otherwise, the only simple way to promote a warning to an error in sbt is to use the -Xfatal-warnings flag:

scalacOptions ++= Seq("-Xfatal-warnings")

But that will convert all warnings in your project to errors, scalastyle or not.

Upvotes: 13

Related Questions