【发布时间】:2014-08-08 11:24:19
【问题描述】:
我正在开发基于 Play 框架构建的网络应用程序。
我想要实现的目标是创建一个像这样工作的自定义 sbt 任务:
- 启动播放应用程序
- 运行我的自定义任务(用 JavaScript 编写的功能测试,取决于正在运行的应用程序)
- 在我的自定义任务完成后停止应用程序
现在我被困在第二步了。
我有这个正在运行的 sbt 脚本:
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)
但如果我尝试通过像这样修改脚本使myCustomTask 依赖于run 任务(启动播放应用程序):
myCustomTask <<= myCustomTask.dependsOn(runTask _)
我收到以下错误:
错误:类型不匹配;找到:(sbt.Configuration,字符串, Seq[String]) => sbt.Def.Initialize[sbt.Task[Unit]] 需要: sbt.Scoped.AnyInitTask (扩展为) sbt.Def.Initialize[sbt.Task[T]] forSome { type T }
我应该如何解决这个问题?
最后,我得到了一个这样的 specs2 类:
"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),
_ => ())
}
【问题讨论】:
-
为什么runTask后面有下划线?
-
@Christian 当我省略 _ 时,sbt 抱怨没有足够的参数
-
我不是游戏专家,但也许你应该使用 run 而不是 runTask(请参阅下面的答案)。
-
@Christian 是的,我试过了,它们都不起作用。请参阅下面的评论
标签: scala playframework sbt