如何在Play 2.3中使用publish / publishLocal发布webjar资产?

时间:2014-09-28 20:44:03

标签: sbt playframework-2.3

Since Play Framework 2.3 assets are packaged into one jar archive file.我想在项目中自动发布这个jar,即publishpublishLocal我想要发布资产jar。

如何实现?

1 个答案:

答案 0 :(得分:2)

inspect tree dist后,我设法找到生成资源文件的任务playPackageAssets

[play-publish-webjar] $ inspect playPackageAssets
[info] Task: java.io.File
[info] Description:
[info]
[info] Provided by:
[info]  {file:/Users/jacek/sandbox/play-publish-webjar/}root/*:playPackageAssets
[info] Defined at:
[info]  (sbt.Defaults) Defaults.scala:641
[info] Dependencies:
[info]  *:playPackageAssets::packageConfiguration
[info]  *:playPackageAssets::streams
[info] Reverse dependencies:
[info]  *:scriptClasspath
[info]  universal:mappings
[info] Delegates:
[info]  *:playPackageAssets
[info]  {.}/*:playPackageAssets
[info]  */*:playPackageAssets

一个天真的解决方案可能是附加资产webjar,因为playPackageAssets生成publishLocal任务的工件。将以下内容添加到build.sbt(类型将显示您使用的内容):

import play.PlayImport.PlayKeys._

packagedArtifacts in publishLocal := {
  val artifacts: Map[sbt.Artifact, java.io.File] = (packagedArtifacts in publishLocal).value
  val assets: java.io.File = (playPackageAssets in Compile).value
  artifacts + (Artifact(moduleName.value, "asset", "jar", "assets") -> assets)
}

对要表现出类似行为的其他任务重复此步骤。

但我很怀疑它是最好的解决方案。