Terminating a run or test in Scala Build Tool (SBT)

When running a program or test in SBT, if you want to exit from it (and not from SBT) try adding following lines in your build.sbt file:
fork := true

To directly add forking in an SBT session, type
set fork := true

This will not detach and open a new consule from the original sbt console.
But, users can kill this separately.
The way to do this in Max OS or Windows is to search a Java process with command line having sbt-launch in Activity Monitor / Windows Task Manager, and end it.
In Unix, try grepping a process with sbt-launch in a new terminal, and kill it. Command to do that is:
kill -9 `ps -h | grep java | grep -v sbt-launch | grep -v grep | awk '{print $1}'`

By default, the run or test tasks run in the JVM as sbt. Forking can be used to run these tasks in a child process. By default, a forked process uses the same Java and Scala versions being used for the build and the working directory and JVM options of the current process. SBT documentation page discusses how to enable and configure forking for both run and test tasks. Each kind of task may be configured separately by scoping the relevant keys.

Comments