How can I use ForkOptions in SBT to change the working directory for testing inside a subproject?

I currently have a multi-project SBT build with two projects, one of which has a dependency on the other. The addict has a test in which he needs to load a file from a specific directory structure under his working directory. It uses a relative path in the config file to refer to this directory structure.

The problem is that depending on whether I'm running this test through my IDE (with a subproject-level working directory) or an SBT project-level (with an umbrella-level working directory), the difference is in my test's ability to load this file through its relative path and succeed.

I need to use a relative path so that other developers working on this project can use the registration code out of the box, and the question of duplicating directory structure and contained files at two levels in a project is out of the question. What I really need to do is direct SBT to move the working directory to a subproject when running tests, so that the directory structure can remain the same no matter where the test is initiated.

SBT offers a ForkOptions class ( http://www.scala-sbt.org/0.13.0/api/index.html#sbt.ForkOptions ) described here: http://www.scala-sbt.org/0.13/docs /Forking.html at the bottom of the page through which it appears to be possible to provide a working directory for a forked JVM to run, but does not provide good examples of how to set up configuration in the root .sbt assembly or provide an instance of ForkOptions for a test task.

Does anyone have any experience with this class and / or can anyone suggest some guidelines for getting this functionality from a multi-project build in SBT?

+3


source to share


1 answer


The solution is to provide the following parameters to define the project in the root assembly .sbt.

lazy val yourProject = project.settings(
    fork := true,
    baseDirectory in test := file("yourProject")
)

      



This calls the JVM fork for the tests in this subproject and changes the working directory to the base of this subproject.

0


source







All Articles