Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change a variable in the current sbt task scope

Tags:

scala

sbt

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
like image 955
Reactormonk Avatar asked May 08 '17 14:05

Reactormonk


1 Answers

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.
like image 200
chengpohi Avatar answered Nov 15 '22 16:11

chengpohi