5

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

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?

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

4

2 回答 2

4
      watchSources <++= baseDirectory map { path => ((path / "src/main/webapp/coffee") ** "*.coffee").get }
于 2013-08-12T04:45:33.877 回答
2

我的 Play 项目有一个非常相似的问题;我希望 SBT和(其中包含Jasmine测试)public/js一样观看对所有 JavaScript 文件的更改。test/js

解决方案是使用 SBT路径查找器表达式来指定位置,如下所示:

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它会返回 a Seq[File],我们将其添加到unmanagedResources(被认为是被监视的源,但不是Scala,这是理想的)

于 2013-07-26T04:43:19.017 回答