Sbt skip tests in a subproject if not run from that project?

I have an SBT project with several sub-projects. One of the subprojects has tests that I don't want to run unless I explicitly do something like "; project xyz; test-only". So if my project structure is:

Main Main / abc main / definition Main / xy

Ideally, running a "test" in main will execute any tests in the main, main / abc and main / def projects, but not in main / xyz.

I tried to add a test filter to the build file for the main class that excludes all tests in main / xyz (by package name) and then adds a separate build.sbt file to the main / xyz project to add them back, but that still results to the fact that tests are executed from the top-level project ...


source to share

1 answer

"Aggregation" is the name of a function that makes it test

run in other projects (called aggregated projects or "run dependencies") as well as the current one. More information can be found on the Multi-Project Builds page .

I would create a custom task in the main project that depends on the tasks you want to run. For example,

myTestTask <<= Seq(
  test in (main, Test),
  test in (abc, Test),
  test in (deff, Test)


where val myTestTask = TaskKey[Unit]("my-test-task")

and main, abc, and deff

are links to your projects.

Aggregation applies only to the top-level task specified on the command line. This way, if you call it my-test-task

, it will be the only task aggregated (in which case it will not be defined in any subprojects, so no tasks will be added via aggregation). In particular, its dependencies, explicitly listed tasks test

, do not become aggregated. The consequence is that it test in xyz

doesn't get executed when you call my-test-task


Finally, note that xyz/test-only

you can run test-only

for a project xyz

without changing that project.



All Articles