【问题标题】:make sbt build fail on scalastyle warnings在 scalastyle 警告上使 sbt 构建失败
【发布时间】:2016-09-12 20:41:56
【问题描述】:

我正在对我的代码空间执行 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 警告上失败

我只是将scalastyleGenerateConfig 中的所有&lt;check level="warning" ...&gt; 更改为&lt;check level="error" ...&gt;,我不确定这是不是正确的做法。

非常感谢

【问题讨论】:

    标签: scala sbt scalastyle


    【解决方案1】:

    我能想到的实际上只有两个简单的选项。

    显而易见的一个是更改您的 scalastyle 配置,以便您想要导致构建失败的警告是错误。这就是 scalastyle 配置的真正用途。如果您希望将某些内容视为错误,请将其称为错误! &lt;check level="error" ...&gt; 会给你带来最少的头痛。

    否则,在 sbt 中将警告升级为错误的唯一简单方法是使用 -Xfatal-warnings 标志:

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

    但这会将您项目中的所有警告转换为错误,无论是否为scalastyle。

    【讨论】:

      【解决方案2】:

      sbt插件还有docs中提到的2个相关配置:

      1. scalastyleFailOnWarning 默认值为 false
      2. scalastyleFailOnError 默认为真(文档说假,但代码说真)

      【讨论】:

        猜你喜欢
        • 2015-06-13
        • 2016-10-01
        • 2017-08-20
        • 1970-01-01
        • 1970-01-01
        • 2020-09-29
        • 2019-07-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多