当我运行我的测试时,我的特殊资源目录的内容special-resources
被复制到该target/classes
目录.我有类似的东西
unmanagedResourceDirectories in Compile += baseDirectory.value / "special-resources",
Run Code Online (Sandbox Code Playgroud)
但我不想将这些资源复制到target
目录中,但我希望它们位于分叉java进程的类路径上(例如用于测试).
我试过用
unmanagedClasspath in Compile += baseDirectory.value / "special-resources",
Run Code Online (Sandbox Code Playgroud)
但资源不可用.
如何在不必复制文件的情况下将资源目录添加到类路径?或者,或者,如何设置sbt以不将资源复制到目标目录?
Jac*_*ski 10
要使special-resources
测试和runMain
任务的类路径中包含目录的内容,请执行以下操作:
unmanagedClasspath in Test += baseDirectory.value / "special-resources"
unmanagedClasspath in (Compile, runMain) += baseDirectory.value / "special-resources"
Run Code Online (Sandbox Code Playgroud)
检查设置是否正确设置show
:
> show test:unmanagedClasspath
[info] List(Attributed(C:\dev\sandbox\runtime-assembly\special-resources))
Run Code Online (Sandbox Code Playgroud)
通过以下Specs2测试,我确信设置工作正常:
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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
hello.txt
在里面special-resources
有一个hello world
字符串的目录中.
> ; 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
Run Code Online (Sandbox Code Playgroud)
而且build.sbt
:
unmanagedClasspath in Test += baseDirectory.value / "special-resources"
libraryDependencies += "org.specs2" %% "specs2" % "2.4" % "test"
fork in Test := true
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10256 次 |
最近记录: |