从“sbt test”运行测试时,类路径与从IDEA运行时不同

时间:2021-01-27 15:43:38

I have the following simple test:

我有以下简单的测试:

class ClasspathTest extends FlatSpec with Matchers {

  "The classpath" should "have more than one member" in {
    System.getProperty("java.class.path").split(":").length should be > 1
  }
}

This resides in an sbt project. When running this from IDEA, this test succeeds because it contains all the libraryDependencies I specified in build.sbt.

这属于一个sbt项目。从IDEA运行此测试时,此测试成功,因为它包含我在build.sbt中指定的所有libraryDependencies。

However, when doing sbt test it fails because it only contains /opt/sbt/bin/sbt-launch.jar.

但是,在进行sbt测试时,它会失败,因为它只包含/opt/sbt/bin/sbt-launch.jar。

Now I have a test which depends on this runtime classpath being fully populated.

现在我有一个测试,它依赖于完全填充的运行时类路径。

Is it possible to populate it somehow?

是否有可能以某种方式填充它?

1 个解决方案

#1


This is a duplicate of Real SBT Classpath at Runtime

这是运行时Real SBT Classpath的副本

To make it work, I have to include in my build.sbt:

为了使它工作,我必须包含在我的build.sbt中:

fork in Test := true

#1


This is a duplicate of Real SBT Classpath at Runtime

这是运行时Real SBT Classpath的副本

To make it work, I have to include in my build.sbt:

为了使它工作,我必须包含在我的build.sbt中:

fork in Test := true