简体   繁体   中英

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

I want the test-compile action to put the contents of src/test/resources into target/scala_2.8.1/test-classes.

The reason for this is that I'm running SBT with IntelliJ IDEA, which puts the test-classes directory on the classpath when it runs tests.

My logback-test.xml file (configuration for logback logging framework) lives in src/test/resources, and it's not being found during testing.

This doesn't directly answer your question, but instead shows an the alternative that I use.

I add two new tasks: prepare and test-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")

I then configure the 'before run' SBT action to these. This requires the idea-sbt-plugin .

替代文字

I use the sbt-idea SBT Processor to configure the IntelliJ module setup. This includes target/scala_2.8.1/[test-]resources as a dependency.

替代文字

While there might be a better way of doing it, this should work as well as long as nothing else overrides testCompile . Just add the following into your project definition.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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