繁体   English   中英

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

[英]How can I change the directory into which SBT puts test resources?

我希望测试编译操作将src / test / resources的内容放入target / scala_2.8.1 / test-classes中。

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

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

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

我添加了两个新任务: 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作为依赖项。

替代文字

尽管可能有更好的方法,但只要没有其他方法可以覆盖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
}
override lazy val testCompile = testCompileAction dependsOn copyTestResources
override def testResourcesOutputPath = testCompilePath

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM