I'm having problem publishing Play's application distribution zip file to remote maven repository.
There are a number of posts and blogs on that, but nothing had seemed to work for me. They are either incomplete or outdated.
For example, here's one excerpt:
val distHack = TaskKey[sbt.File]("dist-hack", "Hack to publish dist")
val myDistSettings = Seq[Setting[_]] (
publish <<= (publish) dependsOn play.Project.dist,
publishLocal <<= (publishLocal) dependsOn play.Project.dist,
artifact in distHack ~= { (art: Artifact) =>
art.copy(`type` = "zip", extension = "zip")
},
distHack <<= (distDirectory, version) map { (d, v) =>
val packageName = "%s-%s" format(projectName, v)
val zip = d / (packageName + ".zip")
zip
}
) ++ Seq(addArtifact(artifact in distHack, distHack).settings: _*)
play.Project.dist is no longer a valid reference to "dist" in the latest version of play.
Also, how do I properly specify "distDirectory" and where do I get "projectName" from?
In addition, most of the examples are geared towards inclusion of the code in the build's .scala file. I'm trying to go simple and specify it in my build's .sbt file.
If this approach worked for anyone, can you please post a complete example?
Thank you!
I use this configuration in build.sbt
to publish the zip file to the remote maven repo.
lazy val dist = com.typesafe.sbt.SbtNativePackager.NativePackagerKeys.dist
publish <<= (publish) dependsOn dist
publishLocal <<= (publishLocal) dependsOn dist
val distHack = TaskKey[File]("dist-hack", "Hack to publish dist")
artifact in distHack ~= { (art: Artifact) => art.copy(`type` = "zip", extension = "zip") }
val distHackSettings = Seq[Setting[_]] (
distHack <<= (target in Universal, normalizedName, version) map { (targetDir, id, version) =>
val packageName = "%s-%s" format(id, version)
targetDir / (packageName + ".zip")
}) ++ Seq(addArtifact(artifact in distHack, distHack).settings: _*)
seq(distHackSettings: _*)
If you want to publish only the zip file, not the other artefacts, add this to build.sbt:
publishArtifact in (Compile, packageBin) := false
publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageSrc) := false
Use sbt publish
to send the zip to the remote repo. Also works like a charm when you use sbt-release.
I would add more details to answer as above answer is missing publish lines.
lazy val dist = com.typesafe.sbt.SbtNativePackager.NativePackagerKeys.dist
val publishDist = TaskKey[sbt.File]("publish-dist", "publish the dist artifact")
publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageSrc) := false
publishArtifact in (Compile, packageBin) := false
publishArtifact in Test := false
publish <<= (publish) dependsOn dist
publishLocal <<= (publishLocal) dependsOn dist
artifact in publishDist ~= {
(art: Artifact) => art.copy(`type` = "zip", extension = "zip")
}
// disable using the Scala version in output paths and artifacts
crossPaths := false
// publish to Artifactory
organization := "your.org.name.modulename"
publishMavenStyle := true
pomIncludeRepository := {
x => false
}
val distHackSettings = Seq[Setting[_]](
publishDist <<= (target in Universal, normalizedName, version) map { (targetDir, id, version) =>
val packageName = "%s-%s" format(id, version)
targetDir / (packageName + ".zip")
},
publishTo := {
val repo = "http://my.artifactory:8081/artifactory/"
if (isSnapshot.value)
Some("snapshots" at repo + "libs-snapshot-local;build.timestamp=" + new java.util.Date().getTime)
else
Some("releases" at repo + "libs-release-local;build.timestamp=" + new java.util.Date().getTime)
}
) ++ Seq(addArtifact(artifact in publishDist, publishDist).settings: _*)
seq(distHackSettings: _*)
//if required provide credentials file location
credentials += Credentials(Path.userHome / ".ivy2" / "credentials")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With