发布由sbt-native-packager创建的zip

时间:2014-02-04 16:47:36

标签: scala sbt sbt-native-packager

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

我像这样配置了我的项目:

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

publishMavenStyle := true

packagerSettings

packageArchetype.java_application

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

2 个答案:

答案 0 :(得分:7)

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

deploymentSettings

根据您的目的,您可能不需要定义可以运行的publishZip任务

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

然后运行sbt publish。

为了完整起见,deploymentSettings(和packagerSettings)来自com.typesafe.sbt.SbtNativePackager,这对于了解您是否使用scala构建非常有用:)

答案 1 :(得分:3)

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)

publishM2 <<= (publishM2) dependsOn (packageBin in Universal)

publishLocal <<= (publishLocal) dependsOn (packageBin in Universal)

此解决方案的关键部分来自comment from yannsdgrandes