How to publish webjar assets with publish/publishLocal in Play 2.3?

谁都会走 提交于 2019-12-07 21:35:48

问题


Since Play Framework 2.3 assets are packaged into one jar archive file. I would like to publish this jar automatically with the project, i.e. upon publish or publishLocal I want the assets jar to be published as well.

How to achieve that?


回答1:


After inspect tree dist I managed to find the task playPackageAssets that generates the assets file:

[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

A naive solution might be to attach the assets webjar as is generated by playPackageAssets to publishLocal task's artifacts. Add the following to build.sbt (the types are to show what you work with):

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)
}

Repeat it for the other tasks you want to exhibit similar behaviour.

I'm however quite doubtful it's the best solution.



来源:https://stackoverflow.com/questions/26089472/how-to-publish-webjar-assets-with-publish-publishlocal-in-play-2-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!