Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass sbt settings as arguments in fullRunTask

Tags:

sbt

How can I get the value of a setting (say, name) and pass it as an argument to fullRunTask? I do not understand the implementation of fullRunTask.

For example:

lazy val foo = TaskKey[Unit]("foo")

fullRunTask(foo, Compile, "foo.Foo", name.value)

does not work because I can't reference name.value in this context.

like image 569
tpolecat Avatar asked Feb 09 '14 08:02

tpolecat


1 Answers

Ok I got some help from Josh Suereth. Doing this with fullRunTask is a little more complex but the extra stuff it does (adding runner in myTask) does wasn't really necessary. Inlining the body of runTask did what I needed.

lazy val myTask = taskKey[Unit]("my custom run task")

myTask := {
  val r = (runner in Compile).value
  val input = name.value // or any other string setting(s)
  val cp = (fullClasspath in Compile).value
  toError(r.run("my.MainClass", data(cp), Seq(input), streams.value.log))
}
like image 92
tpolecat Avatar answered Oct 11 '22 05:10

tpolecat