How to add a custom resource directory to check class paths without copying files inside?

When I run my tests, the contents of the special-resources directory are copied to the target/classes directory. I have something like this

 unmanagedResourceDirectories in Compile += baseDirectory.value / "special-resources", 

But I do not want to copy these resources to the target directory, but I want them to be on the way to the classes of branched java processes (for example, for testing).

I tried using

 unmanagedClasspath in Compile += baseDirectory.value / "special-resources", 

but resources are not available.

How can I add a resource directory to a classpath without copying files? Or alternatively, how can I configure sbt to not copy resources to the destination directory?

+6
source share
1 answer

To have the contents of the special-resources directory included in the classpath for tests and runMain , follow these steps:

 unmanagedClasspath in Test += baseDirectory.value / "special-resources" unmanagedClasspath in (Compile, runMain) += baseDirectory.value / "special-resources" 

Make sure the settings are correct using the show :

 > show test:unmanagedClasspath [info] List(Attributed(C:\dev\sandbox\runtime-assembly\special-resources)) 

In the following Specs2 tests, I am convinced that the setup works fine:

 import org.specs2.mutable._ class HelloWorldSpec extends Specification { "Hello world" should { "find the file on classpath" in { val text = io.Source.fromInputStream(getClass.getResourceAsStream("hello.txt")).mkString text must have size(11) } } } 

hello.txt is located in the special-resources directory with the string hello world inside.

 > ; clean ; test [success] Total time: 0 s, completed 2014-08-06 20:00:02 [info] Updating {file:/C:/dev/sandbox/runtime-assembly/}runtime-assembly... [info] Resolving org.jacoco#org.jacoco.agent;0.7.1.201405082137 ... [info] Done updating. [info] Compiling 1 Scala source to C:\dev\sandbox\runtime-assembly\target\scala-2.10\test-classes... [info] HelloWorldSpec [info] [info] Hello world should [info] + find the file on classpath [info] [info] Total for specification HelloWorldSpec [info] Finished in 17 ms [info] 1 example, 0 failure, 0 error [info] Passed: Total 1, Failed 0, Errors 0, Passed 1 

And build.sbt :

 unmanagedClasspath in Test += baseDirectory.value / "special-resources" libraryDependencies += "org.specs2" %% "specs2" % "2.4" % "test" fork in Test := true 
+8
source

Source: https://habr.com/ru/post/973408/


All Articles