54

I have a multi-module build, and would like to run tests for different sub-projects independently.

Is there a way to do this in sbt, e.g. if my multi-project build has a core and commons projects, I'd like to only run test in the commons project.

6 Answers 6

80

Run sbt commons/test. See detailed explanation in Scopes.

You may also use the combination of two commands from sbt - changing the current project using project and executing test afterwards.

sbt "project commons" test

You can also use

sbt "; project commons; test"
0
15

It you are running sbt in interactive mode:

> project commons
> test

You can switch back to core with:

> project core
6

Never mind, I came across this: How to execute package for one submodule only on Jenkins?

sbt "project core" test
4

Another way to do this.

Get into SBT interactive mode

> sbt

sbt:core> commons / test

No need to switch between projects.

1

to run sbt test only for ONLY the submodules having added, modified on deleted files, if you use git:

 while read -r proj ; do sbt "project $proj" test ; \
 done < <(git status --porcelain | cut -c 3- | cut -d/ -f1
1

There is another way to have sbt open for a particular module. Go to the location of the module directory and type in the "sbt" command.

sbt will then open in interactive mode for that module only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.