7

Overview

After looking around the internet for a while, I have not found a good way to omit certain folders from being watched by sbt 1.0.x in a Play Framework application.

Solutions posted for older versions of sbt:

And the release notes for 1.0.2 show that the += and ++= behavior was maintained, but everything else was dropped.


Would love to see if anyone using sbt 1.0.x has found a solution or workaround to this issue. Thanks!

László
  • 3,973
  • 1
  • 13
  • 26
adu
  • 947
  • 1
  • 8
  • 15

1 Answers1

1

Taking the approach of how SBT excludes managedSources from watchSources I was able to omit a custom folder from being watched like so:

watchSources := {
  val directoryToExclude = "/Users/mgalic/sandbox/scala/scala-seed-project/src/main/scala/dirToExclude"
  val filesToExclude = (new File(directoryToExclude) ** "*.scala").get.toSet
  val customSourcesFilter = new FileFilter {
    override def accept(pathname: File): Boolean = filesToExclude.contains(pathname)
    override def toString = s"CustomSourcesFilter($filesToExclude)"
  }

  watchSources.value.map { source =>
    new Source(
      source.base,
      source.includeFilter,
      source.excludeFilter || customSourcesFilter,
      source.recursive
    )
  }
},

Here we use PathFinder to get all the *.scala sources from directoryToExclude:

val filesToExclude = (new File(directoryToExclude) ** "*.scala").get.toSet

Then we create customSourcesFilter using filesToExclude, which we then add to every current WatchSource:

  watchSources.value.map { source =>
    new Source(
      ...
      source.excludeFilter || customSourcesFilter,
      ...
    )
  }

Note the above solution is just something that worked for me, that is, I do not know what is the recommend approach of solving this problem.

Mario Galic
  • 47,285
  • 6
  • 56
  • 98