liosedhel
liosedhel

Reputation: 518

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

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?

Upvotes: 2

Views: 1189

Answers (1)

Jacek Laskowski
Jacek Laskowski

Reputation: 74709

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.

Upvotes: 2

Related Questions