我正在对我的代码空间执行 scalastyle 检查,引用 http://www.scalastyle.org/sbt.html .
在 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
在项目/plugins.sbt 中:
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
当我跑
sbt compile
, scalastyle 正在生成 [warning] ***./utils/ConfigManager.scala: File must end with newline character
,但是 编译还是成功 .有没有办法让
sbt compile
scalastyle 警告失败 ?我就全换了
<check level="warning" ...>
成为 <check level="error" ...>
在 scalastyleGenerateConfig
,我不确定这是正确的方法。非常感谢
最佳答案
我真的只能想到两个简单的选择。
显而易见的一个是更改您的 scalastyle 配置,以便您想要导致构建失败的警告是错误。这就是 scalastyle 配置的真正用途。如果您希望将某些内容视为错误,请称之为错误! <check level="error" ...>
会给你最少的头痛。
否则,在 sbt 中将警告提升为错误的唯一简单方法是使用 -Xfatal-warnings
旗帜:
scalacOptions ++= Seq("-Xfatal-warnings")
但这会将项目中的所有警告转换为错误,无论是否为 scalastyle。
关于scala - 使 sbt 构建因 Scalastyle 警告而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39458489/