如何将Play的“dist”zip文件发布到远程Maven存储库?

时间:2014-10-19 15:38:01

标签: playframework sbt

我在将Play的应用程序分发zip文件发布到远程maven存储库时遇到问题。

有很多帖子和博客,但似乎没有什么对我有用。它们要么不完整要么过时。

例如,这里有一个摘录:

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不再是最新版本游戏中对“dist”的有效引用。

另外,如何正确指定“distDirectory”以及从哪里获取“projectName”?

此外,大多数示例都是为了在构建的.scala文件中包含代码。我想简单地在我的构建的.sbt文件中指定它。

如果这种方法适用于任何人,请您发一个完整的例子吗?

谢谢!

2 个答案:

答案 0 :(得分:7)

我在build.sbt中使用此配置将zip文件发布到远程maven仓库。

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: _*)

如果您只想发布zip文件而不发布其他文物,请将其添加到build.sbt:

publishArtifact in (Compile, packageBin) := false

publishArtifact in (Compile, packageDoc) := false

publishArtifact in (Compile, packageSrc) := false

使用sbt publish将zip发送到远程仓库。当您使用sbt-release时,它也像魅力一样。

答案 1 :(得分:1)

我会添加更多细节来回答,因为上面的答案是缺少发布行。

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