【发布时间】:2014-03-19 17:46:00
【问题描述】:
我有一个 scala 编译器项目。一些测试用例依赖于生成的 jar 文件。 因此,我总是在运行“测试”任务之前手动运行“打包”任务。
如何添加一个 SBT 任务来完成“测试”的工作但将依赖于“包”?
【问题讨论】:
我有一个 scala 编译器项目。一些测试用例依赖于生成的 jar 文件。 因此,我总是在运行“测试”任务之前手动运行“打包”任务。
如何添加一个 SBT 任务来完成“测试”的工作但将依赖于“包”?
【问题讨论】:
sbt 0.12:
将以下内容添加到您的项目设置中:
(test in Test) <<= (test in Test) dependsOn (Keys.`package` in Compile)
这会更改您项目的测试任务。但您也可以定义自己的任务:
val myTestTask = TaskKey[Unit]("my-test-task", "runs package and then test")
然后将其添加到您的项目设置中:
myTestTask <<= (test in Test) dependsOn (Keys.`package` in Compile)
sbt 0.13:
将以下内容添加到您的项目设置中:
(test in Test) := {
(Keys.`package` in Compile).value
(test in Test).value
}
这会更改您项目的测试任务。但您也可以定义自己的任务:
val myTestTask = taskKey[Unit]("runs package and then test")
然后将其添加到您的项目设置中:
myTestTask := {
(Keys.`package` in Compile).value
(test in Test).value
}
【讨论】:
build.sbt:21: error: eof expected but 'package' found. (test in Test) <<= (test in Test) dependsOn package
(test in Test) <<= (test in Test) dependsOn (Keys.`package` in Compile)。这是通常的方式,还是我的设置特有的方式?请注意,省略 Keys 会给我错误 ` 对包的引用不明确。它在同一范围内被导入两次,导入 Keys._ 和导入 sbt._`
package 关键字冲突。
<<=)?