hot swap in sbt project without play-plugin

932 views Asked by At

When I am using play framework, every time I've changed the code, it will take effect automatically by re-compile the code.

However, when I'm using sbt to run a project without play-plugin, it won't take effect.

I'm wondering if there were a way to make sbt project hot swap the changed code.

My build.sbt is as below:

version in ThisBuild := "1.0-SNAPSHOT"

scalaVersion in ThisBuild := "2.11.6"

lazy val `frontend` = (project in file("frontend")).
  enablePlugins(PlayScala).
  enablePlugins(DockerPlugin).
  settings(
    name := "frontend",
    libraryDependencies ++= Dependencies.frontend
  ).dependsOn(`api`).aggregate(`api`)

lazy val `backend` = (project in file("backend")).
  enablePlugins(JavaAppPackaging).
  enablePlugins(DockerPlugin).
  settings(
    name := "backend",
    libraryDependencies ++= Dependencies.backend ++ Seq(cache, ws)
  ).dependsOn(`api`).aggregate(`api`)

lazy val `api` = (project in file("api")).
  settings(
    name := "api",
    libraryDependencies += ws
  )

And what I have configured in intellij idea is like below as a sbt task(I can't post images by now):

"project backend" ~run

However, every time I've changed the code in backend, It won't take effect after I've call backend from the frontend.

I'm wondering how I can solve the problem. Thanks for your guys' help.

3

There are 3 answers

2
marios On

You can have sbt automatically recompiling any changes by invoking it like this: sbt ~compile

4
Soroosh Sarabadani On

If you use ~run, on every change the changeed classes will be compiled and project rerun again. If it does not work, you might explain more about your project and structure.

0
LoranceChen On

Open two SBT window.
The one run ~compile, and another run ~run. Hope it will be help.