md samual
md samual

Reputation: 325

How to auto re-run sbt project in scala

I have created an sbt project to learn simple crud operation using akka-http. First I added simple routes to check if it is working or not.

By running sbt run command, I found that it runs locally without any error.

But when I make some changes to the project (for example: Adding println statement to the running code) it does not auto compiling. Every time I have to exit (ctrl+c) the running sbt. And again run to see the updated code.

So my question is that how to auto compile sbt project while running the project.

Thank you.

Upvotes: 3

Views: 1836

Answers (2)

Krishnadas PC
Krishnadas PC

Reputation: 6519

As of now you can use it like this

  1. cd into your project root dir
  2. Run sbt which will open up the console
  3. Type ~run. The ~ is optional and causes sbt to re-run on every file save, allowing for a fast edit/run/debug cycle. sbt will also generate a target directory which you can ignore.

When you’re finished experimenting with this project, press [Enter] to interrupt the run command. Then type exit or press [Ctrl+D] to exit sbt and return to your command line prompt.

taken from https://docs.scala-lang.org/getting-started/index.html

Upvotes: 0

Krzysztof Atłasik
Krzysztof Atłasik

Reputation: 22595

As far as I know, it's not handled by default by sbt, but there's a plugin for that: sbt-revolver. It will trigger the restart of your application as soon as there are any changes in the source code of your application.

Just add

addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")

in your build.sbt and then start the app with:

sbt ~reStart

Upvotes: 5

Related Questions