5

On a Play Framework 2.2 project that is using sbt-buildinfo to create a BuildInfo.scala file when the project is compiled, how can build.sbt be configured so that Play Framework won't watch the BuildInfo.scala file for changes, and won't restart the server if that file changes?

For instance, if a session is started with:

$ sbt ~run

and the server starts in development mode, and then in another terminal window another sbt session is started (to run another subproject, or just to run other sbt tasks), this second sbt session will update the BuildInfo.scala file, and the first sbt session will detect this and reload the Play project.

So the question is how to exclude BuildInfo.scala from monitoring (but still compile it and include it in the distribution package).

Apparently the watchSources configuration option could help, but after reading the documentation I couldn't figure out how to use it to exclude a file.

Fernando Correia
  • 21,803
  • 13
  • 83
  • 116
  • 1
    Have you tried `watchSources := watchSources.value.filter { _.getName != "BuildInfo.scala" }` ? I tried to reproduce basic setup, and for me the `BuildInfo.scala` file is not watched (you can check your setup by `show watchSources`). – lpiepiora Jan 20 '15 at 08:56
  • 1
    I was able to filter a file out of watchSources with: `val myProject = play.Project(/*etc*/).settings(/*etc*/ watchSources := watchSources.value.filter { _.getName != "FileName.scala" })`. Your hint to use `show watchSources` also helped. I suggest you enter that as an answer and I'll approve it. It answers what I asked in this question, but it doesn't solved my problem, because I found out that `BuildInfo.scala` is not in `watchSources` (it is in `src_managed/`, which is not in `watchSources`), so the project must be restarting for another reason when I open the second session. – Fernando Correia Jan 20 '15 at 13:52

1 Answers1

7

To remove a particular file from being watched you can do in build.sbt:

watchSources := watchSources.value.filter { _.getName != "BuildInfo.scala" }

I tried to reproduce basic setup, and for me the BuildInfo.scala file is not watched. You can see the list of watched sources by issuing show watchSources.

lpiepiora
  • 13,659
  • 1
  • 35
  • 47
  • 5
    So, how to exclude a folder so Play Framework won't watch any files in that folder for changes? – vichsu Feb 24 '15 at 19:36
  • 1
    To exclude the whole folder from being watched, you can use watchSources := (watchSources.value --- baseDirectory.value / "your-folder-here" ** "*").get – Tuan Nguyen Jan 29 '19 at 23:22