我喜欢在顶层定义scalacOptions
,如此(例如,暂时忽略项目轴):
scalacOptions += "-Ywarn-unused-import"
但后来我意识到console
过于严格。所以我试着设置:
scalacOptions in console ~= (_ filterNot (_ == "-Ywarn-unused-import"))
但那不起作用(在REPL中仍有(致命)警告)。
我使用inspect
来尝试理解原因:
> inspect console
[info] Task: Unit
[info] Description:
[info] Starts the Scala interpreter with the project classes on the classpath.
[info] Provided by:
[info] {file:/a/}b/compile:console
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:261
[info] Dependencies:
[info] compile:console::compilers
[info] compile:console::initialCommands
[info] compile:console::fullClasspath
[info] compile:console::taskTemporaryDirectory
[info] compile:console::scalaInstance
[info] compile:console::streams
[info] compile:console::cleanupCommands
[info] compile:console::scalacOptions
[info] Delegates:
[info] compile:console
[info] *:console
[info] {.}/compile:console
[info] {.}/*:console
[info] */compile:console
[info] */*:console
[info] Related:
[info] test:console
注意:console
是
compile:console
compile:console::scalacOptions
然后:
> inspect compile:console::scalacOptions
[info] Task: scala.collection.Seq[java.lang.String]
[info] Description:
[info] Options for the Scala compiler.
[info] Provided by:
[info] {file:/a/}b/compile:scalacOptions
[info] Defined at:
[info] (sbt.Classpaths) Defaults.scala:1593
[info] Reverse dependencies:
[info] compile:console
[info] Delegates:
[info] compile:console::scalacOptions
[info] compile:scalacOptions
[info] *:console::scalacOptions
[info] *:scalacOptions
[info] {.}/compile:console::scalacOptions
[info] {.}/compile:scalacOptions
[info] {.}/*:console::scalacOptions
[info] {.}/*:scalacOptions
[info] */compile:console::scalacOptions
[info] */compile:scalacOptions
[info] */*:console::scalacOptions
[info] */*:scalacOptions
[info] Related:
[info] *:console::scalacOptions
[info] compile:scalacOptions
[info] *:scalacOptions
[info] */*:scalacOptions
[info] test:scalacOptions
注意:compile:console::scalacOptions
是
compile:scalacOptions
*:console::scalacOptions
(这是我定义的)我的问题是如何为控制台的所有配置覆盖scalacOptions
?是否可以更改授权链?
我希望避免设置scalacOptions in (Compile, console)
(因为它会与(Test, console)
重复)或定义一个scalac选项的val。
答案 0 :(得分:16)
我的问题是如何为控制台的所有配置覆盖
scalacOptions
?
我不认为我们可以提供由compile:scalacOptions
提供的Defaults
。唯一具有更高优先级的范围是compile:console::scalacOptions
。
在大多数情况下,人们不希望Compile
和Test
设置跨线,因此配置范围更高优先级我认为不是默认设置。
lazy val commonSettings = Seq(
scalaVersion := "2.11.4",
scalacOptions += "-Ywarn-unused-import",
scalacOptions in (Compile, console) ~= (_ filterNot (_ == "-Ywarn-unused-import")),
scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value
)
是否可以更改授权链?
不,这是不可能的。
BuildStructure中有一个delegates
函数的单个实例,它在加载时初始化并用于所有任务。
订购在Scope.delegates完成。
答案 1 :(得分:1)
我在自动插件中修复了错误的scalac选项:
develop