【问题标题】:Change a variable in the current sbt task scope更改当前 sbt 任务范围内的变量
【发布时间】:2017-05-09 00:33:44
【问题描述】:

这会编译,但不会将scalacOptions 添加到compile 任务中。这样做的正确方法是什么?

compileWall in ThisBuild := Def.task {
  scalacOptions += "-Xfatal-warnings"
  (compile in Compile).value
}.value

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    SBT 设置在 Runtime 中是不可变的,因此我们无法在自定义 Task 中更新 scalacOptions

    http://www.scala-sbt.org/0.13/docs/Full-Def.html#Reminder%3A+it%E2%80%99s+all+immutable

    但是有一种方法可以通过创建自定义配置并在此配置中绑定scalacOptions来实现自定义Task中的更改scalacOptions,例如:

    lazy val MyCompile = config("MyCompile") extend Compile // customize config: MyCompile
    configs(MyCompile) //configs 
    inConfig(MyCompile)(Defaults.configTasks) //inConfig and append the Defaults.configTasks
    
    val compileWall = taskKey[Unit]("compileWall")
    
    compileWall in ThisBuild := {
      (compile in MyCompile).value
    }
    
    scalacOptions in MyCompile := Seq("-Xfatal-warnings") // bind the scalacOptions in customize config.
    

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 2019-01-10
      • 2012-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      相关资源
      最近更新 更多