Change a variable in the current sbt task scope

This compiles, but it doesn't add the scalacOptions to the compile task. What's the correct way to do this?

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

SBT settings is immutable in the Runtime , so we can't update scalacOptions in the customize Task .

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

but There is a way to achieve change scalacOptions in the customize Task by creating the customize config and bind the scalacOptions in this config , like:

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.
链接地址: http://www.djcxy.com/p/39394.html

上一篇: git diff如何在vscode git扩展中工作?

下一篇: 更改当前sbt任务范围中的变量