1

I have an sbt project configured with a build.sbt. When I run tests, a docker container is started with a configuration file available. This is how I wanted to use it in the test (https://www.testcontainers.org/features/files/#volume-mapping):

MyContainer.withClasspathResourceMapping(
    "/myConfigPath/configFile.config",
    "/myConfigPath/configFile.config",
    BindMode.READ_ONLY
  )

For that, I added the configuration file in build.sbt to the jar for tests like this:

.settings(
    Test / packageBin / mappings ++= Seq(
        (rootBaseDir.value / "myConfigPath" / "myFile.config") -> "/myConfigPath/configFile.config"
    )

When I run the test from my terminal with sbt it works, but when I run the test from the Metals's Test Explorer from within VS Code, the following error occurs:

Cause: java.lang.IllegalArgumentException: Resource with path /myConfigPath/configFile.config could not be found on any of these classloaders: [jdk.internal.loader.ClassLoaders$AppClassLoader@277050dc]

I also tried to add the file (folder) with unmanagedClasspath like this:

Test / unmanagedClasspath += rootBaseDir.value / "myConfigPath"

But the same error occurred.

Can anyone give me a hint on how to solve this correctly?

Irina S.
  • 133
  • 8
  • 1
    If you add `myConfigPath` to the unmanaged classpath, my guess is that those files would be available as `/configFile.config` instead. – Jasper-M Mar 11 '22 at 14:01
  • 1
    I have no experience with Scala, SBT or Test Explorer, but I am very confident this problem is unrelated to Testcontainers and explicitly about the classpath. So you can focus your search for a solution to this area. – Kevin Wittek Mar 14 '22 at 08:17

0 Answers0