【问题标题】:How to run "package" before 'test"如何在“测试”之前运行“包”
【发布时间】:2014-03-19 17:46:00
【问题描述】:

我有一个 scala 编译器项目。一些测试用例依赖于生成的 jar 文件。 因此,我总是在运行“测试”任务之前手动运行“打包”任务。

如何添加一个 SBT 任务来完成“测试”的工作但将依赖于“包”?

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    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) &lt;&lt;= (test in Test) dependsOn package
    • 我不得不把它改成(test in Test) &lt;&lt;= (test in Test) dependsOn (Keys.`package` in Compile)。这是通常的方式,还是我的设置特有的方式?请注意,省略 Keys 会给我错误 ` 对包的引用不明确。它在同一范围内被导入两次,导入 Keys._ 和导入 sbt._`
    • @dips 不幸的是与 Scala 的 package 关键字冲突。
    • 我改变了我的答案,所以它可以编译。
    • 如何在 sbt 0.13 语法中做到这一点(避免 &lt;&lt;=)?
    猜你喜欢
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 2020-03-04
    • 2017-04-27
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 2023-01-12
    相关资源
    最近更新 更多