首页 > 解决方案 > sbt 编译失败,选项错误:'-Ywarn-macros:after'

问题描述

使用 build.sbt 文件,例如:

ThisBuild / organization := "com.company"
ThisBuild / version := "1.0.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.11.12"

Global / concurrentRestrictions += Tags.limit(Tags.Test, 1)

Global / scalacOptions ++= Seq("-Ypartial-unification",
                               "-unchecked",
                               "-Xfatal-warnings",
                               "-Ywarn-dead-code",
                               "-Ywarn-inaccessible",
                               "-Ywarn-unused",
                               "-Ywarn-unused-import",
                               "-Ywarn-macros:after")

[error] bad option: '-Ywarn-macros:none'跑步后得到sbt clean compile

如果没有-Ywarn-macros:after,未使用的导入警告会在使用 Circe 宏的文件中引发虚假警告,例如:import io.circe.{ Decoder, Encoder }.

标签: scalasbtcompiler-flagscircescalac

解决方案


-Ywarn-macros直到 Scala 2.12 才添加,因此该错误是意料之中的。

你能升级到 Scala 2.12 吗?如果你被困在 2.11 上,也许你需要在没有-Ywarn-unused-import. (由于 Som Snytt 的不懈努力,随着 2.12.x 系列的进展,未使用的警告总体上得到了极大的改进。)

您可以将使用 Circe 的代码限制在子项目中,然后仅在该子项目中禁用未使用的警告,以便在代码库的其余部分中启用它们。

另一种可能性是尝试https://github.com/ghik/silencer


推荐阅读