57

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.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Brett
  • 5,690
  • 6
  • 36
  • 63

6 Answers6

82

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"
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
17

It you are running sbt in interactive mode:

> project commons
> test

You can switch back to core with:

> project core
mixel
  • 25,177
  • 13
  • 126
  • 165
6

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

sbt "project core" test
Community
  • 1
  • 1
Brett
  • 5,690
  • 6
  • 36
  • 63
4

Another way to do this.

Get into SBT interactive mode

> sbt

sbt:core> commons / test

No need to switch between projects.

Rohit Nandi
  • 768
  • 10
  • 14
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
Yordan Georgiev
  • 5,114
  • 1
  • 56
  • 53
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

etashsingh
  • 11
  • 1