2017-05-08 38 views
7

編譯時會執行此操作,但不會將scalacOptions添加到compile任務中。什麼是正確的方法來做到這一點?更改當前sbt任務範圍中的變量

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

回答

3

SBT設置在運行不變的,所以我們不能更新在定製TaskscalacOptions

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.