【发布时间】:2017-05-09 00:33:44
【问题描述】:
这会编译,但不会将scalacOptions 添加到compile 任务中。这样做的正确方法是什么?
compileWall in ThisBuild := Def.task {
scalacOptions += "-Xfatal-warnings"
(compile in Compile).value
}.value
【问题讨论】:
这会编译,但不会将scalacOptions 添加到compile 任务中。这样做的正确方法是什么?
compileWall in ThisBuild := Def.task {
scalacOptions += "-Xfatal-warnings"
(compile in Compile).value
}.value
【问题讨论】:
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.
【讨论】: