在SBT设置中将目录附加到监视源

时间:2013-06-24 13:09:05

标签: coffeescript playframework-2.0 sbt

我想在watchedSources设置中添加一个目录,以便在我将文件保存到该目录时触发构建任务。

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

我似乎无法解决以下错误:

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?

如何将一系列文件附加到监视来源任务的结果?

2 个答案:

答案 0 :(得分:4)

      watchSources <++= baseDirectory map { path => ((path / "src/main/webapp/coffee") ** "*.coffee").get }

答案 1 :(得分:2)

我的Play项目遇到了类似的问题;我希望SBT观看public/js以及test/js(其中包含Jasmine次测试),以便更改所有JavaScript文件。

解决方案是使用SBT Path Finder表达式来指定位置,如下所示:

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,
...

路径查找器就是这个位:(file("public/js") ** "*.js") - 并且在其上调用get会返回Seq[File],我们会将其添加到unmanagedResources(被视为已被观看)来源,但 Scala,这是理想的)