gpt4 book ai didi

scala - 在 sbt 中,如何在所有配置中覆盖控制台的 scalacOptions?

转载 作者:行者123 更新时间:2023-12-03 11:28:57 25 4
gpt4 key购买 nike

我喜欢定义 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 (这是我定义的)在委托(delegate)链

  • 我的问题是如何覆盖 scalacOptions控制台的所有配置?是否可以更改委托(delegate)链?

    我想避免设置 scalacOptions in (Compile, console) (因为它会为 (Test, console) 重复)或定义一个 val 的 scalac 选项。

    最佳答案

    My question is how do I override scalacOptions for all configurations for console?



    我认为我们不能给出 compile:scalacOptions 的存在。由 sbt 的 Defaults 提供.唯一具有更高优先级的范围是 compile:console::scalacOptions .
    在大多数情况下,人们不会想要 CompileTest设置跨线,所以配置范围更高的优先级我不认为是一个糟糕的默认值。
    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
    )

    Is it possible to change the delegation chain?



    不,这是不可能的。
    有一个 delegates 的实例 BuildStructure中的函数,并且在加载时初始化并用于所有任务。
    订购在 Scope.delegates 中完成.

    关于scala - 在 sbt 中,如何在所有配置中覆盖控制台的 scalacOptions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26940253/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com