我正在使用播放!2.0 和我有一个关于构建系统的问题。我有多个项目的聚合,并且我有一个共享模块,其中包含静态文件和一些被编译成 css 的 .less 文件。
如何将静态文件以及已编译样式表的输出复制到其他项目中?我试图自己理解,但看起来,虽然我可以轻松地将设置应用于项目,但我无法从另一个项目中检索该设置。
我看过剧!2.0键
val playAssetsDirectories = SettingKey[Seq[File]]("play-assets-directories")
val incrementalAssetsCompilation = SettingKey[Boolean]("play-incremental-assets-compilation")
val playExternalAssets = SettingKey[Seq[(File, File => PathFinder, String)]]("play-external-assets")
但我不知道如何使用这些信息来修改我的构建文件。
object ApplicationBuild extends Build {
val appName = "Website"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
)
val common = PlayProject(
appName + "-common", appVersion, path = file("modules/common"),mainLang=SCALA,
lessEntryPoints <<= baseDirectory(_ / "app" / "assets" / "stylesheets" ** "bootstrap.less")
)
val website = PlayProject(
appName + "-website", appVersion, path = file("modules/website"),mainLang=SCALA,
).dependsOn(common)
val adminArea = PlayProject(
appName + "-admin", appVersion, path = file("modules/admin"),mainLang=SCALA,
).dependsOn(common)
val main = PlayProject(
appName, appVersion,appDependencies,mainLang=SCALA
).dependsOn(
website, adminArea
)
}
我基本上想说的是:
website.playExternalAssets += common.playAssetsDirectory(IncludingCompiled)
但这显然是不合法的。
我其实理解多了一点,下面的代码似乎几乎是对的:
val website = PlayProject(
appName + "-website", appVersion, path = file("modules/website"),mainLang=SCALA
).dependsOn(common).settings(playExternalAssets <<= common.playAssetsDirectory(IncludingCompile))
除了 common.playAssetsDirectory 不起作用:
[info] Loading project definition from G:\project1\project [error] G:\project1\project\Build.scala:26: value playAssetsDirectory is not a member of sbt.Project [error] ).dependsOn(common).settings(playExternalAssets <<= common.playA ssetsDirectory(IncludingCompile)) [error] ^ [error] one error found [error] {file:/G:/project1/project/}default-436781/compile:compile: Compilati on failed
看起来这里的问题是键是常量值而不是项目的属性。事实上,键是在 PlayKeys 中定义的常量全局值,所以我实际上需要指定范围但我不知道如何