2

We are using sbt with xsbt-web-plugin to develop our liftweb app. In our project build we have several subprojects and we use dependencies of a Project to share some stuff between all the subprojects.

object ProjectBuild extends Build {
//...

lazy val standalone = Project(
  id = "standalone",
  base = file("standalone"),
  settings = Seq(...),
  dependencies = Seq(core) // please notice this
)

lazy val core = Project(
  id = "core",
  base = file("core"),
  settings = Seq(...)
}
// ...
}

To ease the development we use 'project standalone' '~;container:start; container:reload /' command automatically recompile changed files.

We decided to serve some common assets from shared core project as well. This works fine with lift. But what we faced when added our files to core/src/main/resources/toserve folder, is that any change to any javascript or css file causes application to restart jetty. This is annoying since such reload takes lots of resources.

So I started investigating on how to prevent this, even found someone mentioning watchSources sbt task that scans for changed files.

But adding this code as a watchSources modification (event that println prints all the files) does not prevent from reloading webapp each time I change assets located in core resources folder.

lazy val core = Project(
  id = "core",
  base = file("core"),
  settings = Seq(
    // ...
    // here I added some tuning of watchSources
    watchSources ~= { (ws: Seq[File]) => ws filterNot { path =>
      println(path.getAbsolutePath)
      path.getAbsolutePath.endsWith(".js")
    } }
 )

I also tried adding excludeFilter to unmanagedSorces, unmanagedResorces but with no luck.

I'm not an sbt expert and such modification of settings looks more like a magic for me (rather then a usual code). Also such tuning seem to be uncovered by documentation =( Can anyone please help me to prevent sbt from reloading webapp on each asset file change?

Thanks a lot!

Oleg Stepura
  • 95
  • 2
  • 11

2 Answers2

0

You're on the right track by using watchSources, but you'll also need to exclude the resources directory itself:

watchSources ~= { (ws: Seq[File]) =>
  ws filterNot { path =>
    path.getName.endsWith(".js") || path.getName == ("resources")
  }
}
earldouglas
  • 13,265
  • 5
  • 41
  • 50
  • Hi! Thanks for the suggestion, but this does not help =( Liftweb app still reloads if I edit and save some js file in `core`. – Oleg Stepura Sep 17 '14 at 08:37
  • Where specifically is the *.js* file? Is it in *core/src/main/resources*? – earldouglas Sep 19 '14 at 17:52
  • File is stored in `/core/src/main/resources/toserve/core/js/`, but any file being edited from `/core/src/main/resources/` causes the same behaviour. – Oleg Stepura Sep 22 '14 at 08:15
  • You might need to reuse the `watchSources` filter above in your root project as well. Do you see the same problem when you perform a triggered execution on only the *core* subproject? – earldouglas Sep 22 '14 at 15:19
  • `core` itself does not have container configuration. So doing `'project core' '~;container:start; container:reload /'` does not work (`No such setting/task container:start`). I tried adding same `watchSources` to `standalone` app configuration in `ProjectBuild`, but with no luck (editing any file from core resources folder still causes app reload). – Oleg Stepura Sep 23 '14 at 11:12
  • Hi, James! I created a test use-case for you to experiment. https://yadi.sk/d/NNgWowTnbchbK – Oleg Stepura Sep 23 '14 at 12:09
0

Can you switch from using "resources" folder to using "webapp" folder? That will also free you from restarts. Here's a demo project for Lift (that uses "webapp"):

https://github.com/lift/lift_26_sbt/

For example, the "basic" template:

https://github.com/lift/lift_26_sbt/tree/master/scala_211/lift_basic/src/main/webapp

VasiliNovikov
  • 9,681
  • 4
  • 44
  • 62
  • BTW, sorry for the late answer. The official suppor channel is the mailing list, although I personally try to watch stackoverflow, too. (Had my RSS client broken for 2 weeks). – VasiliNovikov Sep 29 '14 at 17:11
  • This seem not to have any projects where a subproject uses another subproject as a dependency. There is no way to use webapp contents from inside `core` in my example. – Oleg Stepura Sep 30 '14 at 08:21