Override sbt's `fork` setting

Viewed 113

I have an Akka app that has a fork := true setting in build.sbt. So when I need to debug code I set it manually to false. That is something which is easy to forget.

Is there a way to override the fork setting from command line? For example when running sbt clean run. I've read that one can create a separate task and override fork just for that task. In latter case how would the clean run task look like?

Update: Sorry for the confusion. Following Marko's reply I realized that my ticket was incomplete. I would like a way to set this in a non-interactive shell. Right now I have an IntelliJ sbtTask (which also takes environment variables etc.) for which I just click the debug button to run the app. The task itself has only two words in it - clean run, but should need to create a separate one that would be fine.

2 Answers

Consider set command, for example from within sbt shell

set fork := false; clean; run

change will stick until

sbt is restarted, the build is reloaded, or the setting is overridden by another set command or removed by the session command

Mario's answer is very good, but I was curious if there was a single line instruction that I could share with my team. I think I've finally found it thanks to this FAQ item in Sbt documentation.

In build.sbt you can add the following:

lazy val runWithForkFalse = taskKey[Unit]("Run application with `set fork:= false` for debugging purpose.")

runWithForkFalse / fork := false

fullRunTask(runWithForkFalse, Compile, "com.Main")

Then in InelliJ you can create a Sbt task that has only two words clean runWithForkFalse and click on their debug icon. You can also of course just run sbt clean runWithForkFalse from command line.

Related