对于测试,我使用的是内存 NIOFileSystem
实现(memoryfs)。我以前利用过它,它似乎可以通过例如 Maven 运行良好。
但是,现在,在 SBT 项目中,不可能初始化一个新的FileSystem
.
这是重现问题的最小 SBT 配置:
import sbt._
import Keys._
name := "testfs"
organization := "com.example
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.6"
libraryDependencies ++= {
val scalaTestVersion = "2.2.5"
Seq(
"org.scalatest" %% "scalatest" % scalaTestVersion % "test",
"org.mockito" % "mockito-core" % "1.10.19" % "test",
"de.pfabulist.lindwurm" % "memoryfs" % "0.28.3" % "test"
)}
这是一个测试:
import de.pfabulist.lindwurm.memory.MemoryFSBuilder
import org.scalatest.{FlatSpec, MustMatchers}
class FsDummySpec extends FlatSpec with MustMatchers {
it must "init the FS" in {
new MemoryFSBuilder().watchService(true).name("testFs").build() //init here
}
}
运行sbt test
将导致:
[info] FsDummySpec:
[info] - must init the FS *** FAILED ***
[info] java.nio.file.ProviderNotFoundException: Provider "memoryfs" not found
[info] at java.nio.file.FileSystems.getFileSystem(FileSystems.java:224)
[info] at de.pfabulist.kleinod.paths.Pathss.getOrCreate(Pathss.java:76)
事情是这样的:这应该可以毫无问题地运行。我的问题是:为什么,以及如何解决它?
浏览自定义 FS 提供程序文档,看起来 SBT 以某种方式破坏了类路径,但很难说为什么。
注意:有趣的是,IntelliJ IDEA 的测试运行器似乎可以顺利运行,问题仅出在命令行上(在“SBT 正确”中)。