Search code examples
scalasbtscala-3

sbt: Running specific main method from the command line


I have several methods annotated with @main and it totally beats me how to run one of them specifically from a terminal, even after thoroughly looking at the sbt documentation. All I can find is how to specify what source file my main class is in. My project contains only one file though, so this is not really helpful.

Assume I have the following (where root being the project's root directory of course):

├── root
│   └── src
│       └── main
│           └── scala
│               └── main.scala

and main.scala looks something like this:

object main:
  @main def foo(): Unit = ???
  @main def bar(): Unit = ???

Is the only way to run either foo or bar from a shell to distribute up my methods over several files? 🤔


Solution

  • You may run either methods from inside SBT shell via:

    runMain foo
    

    or

    runMain bar