簡體   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