3

如果代码库中有任何未使用的导入、本地或私有变量或死代码,我会尝试编译失败。所以,我添加了以下 scalacoptions。

scalacOptions ++= Seq(
        "-encoding", "UTF-8",
        "-Xfatal-warnings",
        "-Xlint:-unused,_",
        "-Ywarn-dead-code",
        "-Ywarn-unused:imports",             // Warn if an import selector is not referenced
        "-Ywarn-unused:locals",              // Warn if a local definition is unused
        "-Ywarn-unused:patvars",             // Warn if a variable bound in a pattern is unused
        "-Ywarn-unused:privates",            // Warn if a private member is unused
        "-deprecation"
      )

但是每当我编译我的项目时,它都会编译失败并给出以下错误。

[error] 'imports' is not a valid choice for '-Ywarn-unused'
[error] bad option: '-Ywarn-unused:imports'

斯卡拉版本:2.11.11

我不确定我在做什么错误。

4

1 回答 1

1

以下设置应该可以工作 -

    lazy val project_name = project.in(file(".")).settings(commonSettings)

    lazy val commonSettings = reformatOnCompileSettings ++ Seq(
    scalacOptions ++= Seq(
        "-Ywarn-unused-import",
        "-language:postfixOps",
        "-Ypartial-unification"
    )
    )

希望这可以帮助。

于 2019-04-10T07:34:25.883 回答