1

我有一个单项目构建,在 Build.scala 文件中实现,具有以下设置: scala lazy val root = Project( id = ProjectInfo.name, base = file("."), settings = Project.defaultSettings ++ Revolver.settings ++ Revolver.enableDebugging(port = 5050) ++ Twirl.settings ++ // more tasks omitted ++ Seq( mainClass in Compile := Some(launcherClassName), mainClass in Revolver.reStart := Some(launcherClassName), javaOptions in Revolver.reStart ++= List( "-XX:PermSize=256M", "-XX:MaxPermSize=512M", "-Dlogback.debug=false", "-Dlogback.configurationFile=src/main/resources/logback.xml" ), resolvers ++= projectResolvers, libraryDependencies ++= Dependencies.all, parallelExecution in Test := false, ) )

我想为项目添加 sbt-web 托管资产处理,因为我想处理咖啡脚本,等等。

我将sbt-coffeescript插件直接添加到plugins.sbt文件project夹中的文件中,并且实际上可以正常工作。所以现在当我运行时,web-assets:assets我有一个咖啡脚本示例文件/src/main/coffeescript/foo.coffee,它被编译为target/web/coffeescript/main/coffeescript/foo.js.

不幸的是,当我简单地运行compilerun执行任务时,什么都没有得到处理。如何compile在开发工作流程中启用资产处理?

4

2 回答 2

2

您遇到的问题是在项目中指定依赖项的旧样式不适用于 AutoPlugins(这就是 WebPlugin)。

具体来说:

val foo = Project(
    id = "ok"
    base = file("ok")
    settings = defaultSettings // BAD!
)

即,如果您在项目上手动放置设置,您就是在告诉 sbt “我知道我想要在这个项目上的所有设置,并且我想完全覆盖默认设置。”

sbt设置的加载顺序为:

  1. AutoPlugins(核心设置现在来自 AutoPlugins)
  2. Project实例中定义的设置
  3. build.sbt在项目基目录中的文件中定义的设置。

上面的代码重新应用了 0.13.x 系列的所有 sbt 默认设置,这将覆盖 AutoPlugins 之前启用的任何内容。这是设计使然,因为任何其他机制都不会“正确”。

如果您要迁移到使用 AutoPlugins,只需将您的构建修改为:

lazy val root = Project(
  id = ProjectInfo.name,
  base = file("."))
  settings = 
    // NOTICE we dropped the defaultSettings
    Revolver.settings   
    ++ Revolver.enableDebugging(port = 5050)
    ++ Twirl.settings
    ++ // more tasks omitted
    ++ Seq(
      mainClass in Compile := Some(launcherClassName),
      mainClass in Revolver.reStart := Some(launcherClassName),
      javaOptions in Revolver.reStart ++= List(
        "-XX:PermSize=256M",
        "-XX:MaxPermSize=512M",
        "-Dlogback.debug=false",
        "-Dlogback.configurationFile=src/main/resources/logback.xml"
      ),
      resolvers ++= projectResolvers,
      libraryDependencies ++= Dependencies.all,
      parallelExecution in Test := false,
   )
)
于 2014-09-11T12:16:35.727 回答
1

为了在编译时运行资产生成,我这样做了:

settings = ... ++ Seq(
  pipelineStages := Seq(rjs),
  (compile in Compile) <<= compile in Compile dependsOn (stage in Assets),
  // ...
)

比我运行编译时,stage命令也被执行,从而运行 sbt-web 的管道。我的问题是如何使生成的资产作为托管资源的一部分可用(我正在尝试sbt-web使用xsbt-web-pluginand liftweb

于 2014-10-10T10:54:29.333 回答