Add file to classpath of testcontainer in VS Code / Metals using build.sbt

642 views Asked by At

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?

0

There are 0 answers