我有一个多项目 sbt 构建,我想使用https://github.com/softprops/coffeescripted-sbt将我的咖啡脚本编译为 javascript,但它没有执行任务。
代码取自https://github.com/jeffmay/angular-play-multimodule-seed/tree/stackoverflow-17289043
使用 build.sbt
即使不推荐,我还是将项目目录中的 build.sbt 文件与我的项目对象混合在一起,以测试此插件是否有效。
在build.sbt
:
seq(coffeeSettings: _*)
当我跑的时候:
$ sbt
[info] Loading project definition from /Users/jeffmay/code/righttrack/project
[info] Set current project to root (in build file:/Users/jeffmay/code/righttrack/)
> coffee
[success] Total time: 0 s, completed Jun 24, 2013 11:40:37 PM
> show coffee
[info] ArrayBuffer()
[success] Total time: 0 s, completed Jun 24, 2013 11:40:52 PM
> project web
[info] Set current project to web (in build file:/Users/jeffmay/code/righttrack/)
[web] $ coffee
[error] Not a valid command: coffee
[error] No such setting/task
[error] coffee
[error] ^
[web] $
是什么ArrayBuffer()
意思?这是一个无声的失败(咖啡脚本返回最后一个表达式,否则它会是 a return;
?null
)
多项目设置
在某些情况下,我的构建是这样分解的......
在project/plugins.sbt
:
// SBT community plugin resolver
resolvers += Resolver.url("sbt-plugin-releases",
new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
// CoffeeScript compiler plugin
addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "0.2.3")
在project/Modules.scala
(我的构建对象)中:
import sbt._
object Modules extends Build {
lazy val root = RootModule.project
lazy val api = ApiModule.project
lazy val web = WebModule.project
}
在project/WebModule.scala
:
object WebModule extends BaseModule {
// ... libraries dependencies and stuff
override def project = play.Project(moduleName, moduleVersion, libraries, file(location),
moduleSettings ++
Seq((resourceManaged in (Compile, CoffeeKeys.coffee)) <<= (crossTarget in Compile)(_ / "src" / "main" / "coffee"))
)
}
我使用 aproject/BaseModule.scala
来消除每个模块的公共元素的混乱,但它并没有做任何花哨的事情。
使用 Build.scala
我删除了build.sbt
这些东西,并Build.scala
通过project/WebModule.scala
添加:
override def project = play.Project(moduleName, moduleVersion, libraries, file(location),
moduleSettings ++
coffeeSettings ++ // With the settings moved from build.sbt
Seq((resourceManaged in (Compile, CoffeeKeys.coffee)) <<= (crossTarget in Compile)(_ / "src" / "main" / "coffee"))
)
然后我试一试
$ sbt
[info] Loading project definition from /Users/jeffmay/code/righttrack/project
[info] Set current project to root (in build file:/Users/jeffmay/code/righttrack/)
> coffee
[error] Not a valid command: coffee
[error] No such setting/task
[error] coffee
[error] ^
> project web
[info] Set current project to web (in build file:/Users/jeffmay/code/righttrack/)
[web] $ coffee
[success] Total time: 0 s, completed Jun 25, 2013 12:08:36 AM
[web] $ show coffee
[info] ArrayBuffer()
[success] Total time: 0 s, completed Jun 25, 2013 12:08:40 AM
运行咖啡命令后我没有看到任何变化。任何想法是什么问题?
谢谢!