How to run an SBT task prefixed with a configuration in batch mode?

Viewed 540

In SBT interactive mode I can prefix tasks with configuration names (scoped commands):

$ sbt
> compile
> Compile / compile
> Test / compile

I can also run tasks in batch mode (non-interactive mode)

$ sbt compile

but running

$ sbt Test / compile

gives an error

[info] Executing in batch mode. For better performance use sbt's shell
[error] Not a valid command: Test (similar: set, last, exit)
[error] Not a valid project ID: Test
[error] Expected ':'
[error] Expected '/'
[error] Not a valid key: Test (similar: test, testOnly, dist)
[error] Test
[error]     ^

How do I run configuration-prefixed tasks in batch mode in SBT?

1 Answers

To run configuration-level tasks in batch mode try using test: prefix like so

sbt test:compile
sbt test:clean test:compile

or surrounded with quotes

sbt "Test / compile"
sbt ";Test / clean; Test / compile"

Also we could set configuration scope once and then all subsequent commands would be scoped to this configuration like so

sbt ";set configuration := Test; clean; compile"
Related