7

我正在尝试通过Universal:packageBin任务将sbt-native-packager插件生成的 zip 文件发布到存储库。

我这样配置我的项目:

publishTo := Some("Repo" at "http://repo")

publishMavenStyle := true

packagerSettings

packageArchetype.java_application

我正在努力尝试使用发布任务和 packageBin 任务创建一个新的 sbt 任务(名为 publishZip)来发布 zip 文件。我怎样才能做到这一点?

4

2 回答 2

7

将以下行添加到您的 sbt 构建中(围绕 packagerSettings 应该没问题)

deploymentSettings

根据您想要执行的操作,您可能不需要定义可以运行的 publishZip 任务

  • sbt universal:publish应该只发布 zip
  • 重新定义发布,使其依赖于universal:publish,它将发布所有项目工件 publish <<= publish.dependsOn(publish in config("universal"))

然后运行 ​​sbt 发布。

为了完整起见deploymentSettings(和packagerSettings)来自com.typesafe.sbt.SbtNativePackager哪个有助于了解您是否使用 scala 构建:)

于 2014-02-05T11:41:24.310 回答
6

但是deploymentSettings我想改进设置。似乎有几个问题正在发生。我终于想出了以下解决方案:

//--use sbt-native-packager default java application 
packageArchetype.java_application

//--a dummy task to hold the result of the universal:packageBin to stop the circular dependency issue
val packageZip = taskKey[File]("package-zip")

//--hard coded result of "universal:packageBin"
packageZip := (baseDirectory in Compile).value / "target" / "universal" / (name.value + "-" + version.value + ".zip")

//--label the zip artifact as a zip instead of the default jar
artifact in (Universal, packageZip) ~= { (art:Artifact) => art.copy(`type` = "zip", extension = "zip") }

//--add the artifact so it is included in the publishing tasks
addArtifact(artifact in (Universal, packageZip), packageZip in Universal)

//--make sure the zip gets made before the publishing commands for the added artifacts
publish := (publish dependsOn (packageBin in Universal)).value

publishM2 := (publishM2 dependsOn (packageBin in Universal)).value

publishLocal := (publishLocal dependsOn (packageBin in Universal)).value

该解决方案的关键部分来自 yannsdgrandes的评论

于 2014-11-11T16:40:37.647 回答