确保“重新启动”任务在它之前自动运行:test

时间:2014-01-23 12:19:47

标签: scala sbt

在运行IntegrationTest目标(re-start)之前,是否可以让it:test(又名重启)任务自动运行?

我以为会这样做:

test <<= (test in IntegrationTest) dependsOn reStart

但是,我收到了这个错误:

build.sbt:54: error: not found: value reStart
test <<= (test in IntegrationTest) dependsOn reStart
                                             ^
[error] Type error in expression

通过添加import Revolver._,我得到了更多,但它仍然失败。现在我得到一个更具描述性的错误:

build.sbt:55: error: type mismatch;
 found   : sbt.InputKey[spray.revolver.AppProcess]
 required: sbt.Scoped.AnyInitTask
    (which expands to)  sbt.Def.Initialize[sbt.Task[T]] forSome { type T }
test in IntegrationTest <<= (test in IntegrationTest) dependsOn reStart

有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:2)

您可以为此定义特殊TaskKey类型的任务(working example):

lazy val reStart0 = TaskKey[AppProcess]("re-start-0")
lazy val emptyArgs = SettingKey[revolver.Actions.ExtraCmdLineOptions]("empty-args")

lazy val projectA = Project(
  id = "hello-a",
  base = file("./a"),
  settings = Project.defaultSettings ++ Revolver.settings
).settings(
  emptyArgs := revolver.Actions.ExtraCmdLineOptions(Nil, Nil),
  reStart0 <<= {
  (streams, Revolver.reLogTag, thisProjectRef, Revolver.reForkOptions, mainClass in Revolver.reStart, fullClasspath in Runtime, Revolver.reStartArgs, emptyArgs)
     .map(revolver.Actions.restartApp)
     .dependsOn(products in Compile)
  }
)

lazy val projectB = Project(
  id = "hello-b",
  base = file("./b"),
  settings = Project.defaultSettings ++ Revolver.settings ++ Defaults.itSettings)
.configs(IntegrationTest)
.settings(
  test in (IntegrationTest) <<= (test in IntegrationTest).dependsOn(reStart0 in projectA)
)