Reputation: 8305
I am working on a web app that's built atop Play Framework.
The goal I want to achieve is to create a custom sbt task that works like this:
Now I am stuck on step two.
I have this sbt script that's working:
lazy val anotherTask = taskKey[Unit]("run this first")
lazy val myCustomTask = taskKey[Unit]("try to run shell in sbt")
anotherTask := {
println("i am the first task")
}
myCustomTask := {
println("try to run shell")
import scala.sys.process._
println("git status" !!)
println("the shell command worked, yeah!")
}
myCustomTask <<= myCustomTask.dependsOn(anotherTask)
But if I try to make myCustomTask
depend on the run
task (which starts the play app) by modifying the script like this:
myCustomTask <<= myCustomTask.dependsOn(runTask _)
I get the following error:
error: type mismatch; found : (sbt.Configuration, String, Seq[String]) => sbt.Def.Initialize[sbt.Task[Unit]] required: sbt.Scoped.AnyInitTask (which expands to) sbt.Def.Initialize[sbt.Task[T]] forSome { type T }
How should I solve this problem?
At last, I ended up with a specs2 class like this:
"my app" should {
"pass the protractor tests" in {
running(TestServer(9000)) {
Await.result(WS.url("http://localhost:9000").get, 2 seconds).status === 200
startProtractor(getProcessIO) === 0
}
}
}
private def startProtractor(processIO: ProcessIO): Int = {
Process("protractor", Seq( """functional-test/config/buildspike.conf.js"""))
.run(processIO)
.exitValue()
}
private def getProcessIO: ProcessIO = {
new ProcessIO(_ => (),
stdout => fromInputStream(stdout).getLines().foreach(println),
_ => ())
}
Upvotes: 2
Views: 887
Reputation: 13749
Run is an Input Task, if you want to use it in conjunction with a normal task, you have to convert it to a task first.
You can get a task from an input task by using toTask
method as it is described in the documentation.
myCustomTask <<= myCustomTask.dependsOn((run in Compile).toTask(""))
Upvotes: 4
Reputation: 74709
I would use the following to depend on the run
task:
myCustomTask <<= myCustomTask dependsOn run
While changing the build I would also use sbt.Process API to execute git status
.
"git version".!
It's supposed to be working fine(r) with the changes.
Upvotes: 0