0
votes

I'm attempting to allow my application to use System.exit(<int>) so that when run via the command line on it's own outside of SBT it return a useful exit code.

When I exit whilst running through SBT's run command I get the following message:

Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "run-main-e"

I am aware of what this message is there for, and why it must be there.

I would like to avoid exiting if my code is being run via SBT. Is it possible to detect whether or not code is being run via SBT? If so, how?

1
Your main can inspect the stack for sbt, Thread.currentThread.getStack.som-snytt

1 Answers

3
votes

You can solve this problem by using SBT's fork setting. In your build.sbt, add:

fork := true

For further refinement on which tasks to fork, consult SBT's documentation: http://www.scala-sbt.org/0.13/docs/Forking.html