如何更改SBT放置测试资源的目录?

时间:2011-01-21 03:59:46

标签: scala intellij-idea sbt

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

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

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

3 个答案:

答案 0 :(得分:4)

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

我添加了两项新任务: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

alt text

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

alt text

答案 1 :(得分: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
}

答案 2 :(得分:1)

override lazy val testCompile = testCompileAction dependsOn copyTestResources
override def testResourcesOutputPath = testCompilePath