【问题标题】:How can I change the directory into which SBT puts test resources?如何更改 SBT 放置测试资源的目录?
【发布时间】:2011-01-21 03:59:46
【问题描述】:

我希望 test-compile 操作将 src/test/resources 的内容放入 target/scala_2.8.1/test-classes。

原因是我使用 IntelliJ IDEA 运行 SBT,它在运行测试时将 test-classes 目录放在类路径中。

我的 logback-test.xml 文件(logback 日志框架的配置)位于 src/test/resources 中,在测试期间找不到。

【问题讨论】:

    标签: scala intellij-idea sbt


    【解决方案1】:

    这不会直接回答您的问题,而是显示我使用的替代方法。

    我添加了两个新任务:preparetest-prepare

    lazy val prepare = task{
      None
    } dependsOn (compile, copyResources) describedAs ("Compiles main, copies main resources. Use for the before-action in the idea-sbt-plugin")
    
    lazy val testPrepare = task{
      None
    } dependsOn (testCompile, copyResources, copyTestResources) describedAs ("Compiles main and test, copies all resources. Use for the before-action in the idea-sbt-plugin")
    

    然后我为这些配置“运行前”SBT 操作。这需要idea-sbt-plugin

    我使用sbt-idea SBT 处理器来配置 IntelliJ 模块设置。这包括 target/scala_2.8.1/[test-]resources 作为依赖项。

    【讨论】:

    • IDEA 构建过程将资源复制到classestest-classes 目录,这很烦人,因为这样你最终会得到两组资源。
    【解决方案2】:

    虽然可能有更好的方法,但只要没有其他任何东西覆盖testCompile,它应该可以正常工作。只需将以下内容添加到您的项目定义中即可。

    override lazy val testCompile = testCompileAction dependsOn task {
      import sbt.Process._
      "cp -R src/test/resources/* target/scala_2.8.1/test-classes" ! log
      None
    }
    

    【讨论】:

      【解决方案3】:
      override lazy val testCompile = testCompileAction dependsOn copyTestResources
      override def testResourcesOutputPath = testCompilePath
      

      【讨论】:

      • 将测试资源复制到 testCompilePath 的唯一问题是编译器会在每次运行时检测到修改,从而大大减慢速度。
      猜你喜欢
      • 2012-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多