Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending a directory to watch-sources in SBT settings

I would like to add a directory to the watchedSources setting to trigger a build task whenever I save a file in that directory.

override def baseProject = play.Project(
  moduleName,
  moduleVersion,
  dependencies = libraries,
  path = file(location),
  settings = moduleSettings ++ Seq(
    watchSources <++= baseDirectory map { dir =>
      Seq(
        dir / "src/main/javascript"
      )
    }
  )
)

I can't seem to get around the following error:

type mismatch;
[error]  found   : sbt.Project.Initialize[ScalaObject with Equals]
[error]  required: sbt.Project.Initialize[sbt.Task[?]]
[error] Note: ScalaObject with Equals >: sbt.Task[?], but trait Initialize is invariant in type T.
[error] You may wish to define T as -T instead. (SLS 4.5)
[error]     watchSources <++= baseDirectory { f =>
[error]                                     ^
[error] one error found
[error] (compile:compile) Compilation failed
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?

How do I append a sequence of files to the result of the watched sources task?

like image 861
Jeff May Avatar asked Jun 24 '13 13:06

Jeff May


Video Answer


2 Answers

      watchSources <++= baseDirectory map { path => ((path / "src/main/webapp/coffee") ** "*.coffee").get }
like image 175
user2673683 Avatar answered Nov 15 '22 08:11

user2673683


I had a very similar problem with my Play project; I want SBT to watch public/js as well as test/js (which contains Jasmine tests), for changes to ALL JavaScript files.

The solution is to use an SBT Path Finder expression to nominate the locations as follows:

val main = play.Project(appName, appVersion, appDependencies, settings = Defaults.defaultSettings ++ buildInfoSettings ++ scctSettings).settings(
testOptions in Test += Tests.Argument("junitxml", "console"),
unmanagedResources in Compile ++= (file("public/js") ** "*.js").get,
unmanagedResources in Test ++= (file("test/js") ** "*.js").get,
...

The Path Finder is this bit: (file("public/js") ** "*.js") - and calling get on it returns a Seq[File], which we add to the unmanagedResources (which are considered to be watched sources, but not Scala, which is ideal)

like image 30
millhouse Avatar answered Nov 15 '22 09:11

millhouse