7

I am trying to publish to a repository the zip file generated by the sbt-native-packager plugin through universal:packageBin task.

I configured my project like this:

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

publishMavenStyle := true

packagerSettings

packageArchetype.java_application

I am struggling trying to create a new sbt task (named publishZip) using publish task and packageBin task to publish the zip file. How can I achieve this ?

1

2 Answers 2

7

Add the following line to your sbt build (around packagerSettings should be fine)

deploymentSettings

Depending on what you want to do you may not need to define the publishZip task you could run

  • sbt universal:publish which should only publish the zip
  • redefine publish so it depends on universal:publish which would publish all the projects artifacts publish <<= publish.dependsOn(publish in config("universal"))

Then run sbt publish.

For completeness sake deploymentSettings (and packagerSettings) come from com.typesafe.sbt.SbtNativePackager which is useful to know if you use a scala build :)

3
  • I tried universal:publish but it only publishes javadoc, jar, sources and pom files. Do I miss a specific configuration ?
    – JLM
    Feb 5, 2014 at 17:08
  • Sorry I missed the lack of deploymentSettings, I have edited my answer with the necessary information.
    – Jean
    Feb 5, 2014 at 20:55
  • If you are using a newer version then you need to add the UniversalDeployPlugin to your project instead of using deploymentSettings Mar 22, 2018 at 16:46
6

The deploymentSettings worked however I wanted to refine the settings. It seems there were several issues going on. I and finally came up with the following solution:

//--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

The key pieces of this solution came from a comment from yanns and dgrandes

2
  • 1
    For those seeing this now (2020). The <<= syntax has been deprecated. For example the publish step should now be written as: "publish := (publish dependsOn (packageBin in Universal)).value" Jan 7, 2020 at 1:36
  • 1
    Thank you Michael, I updated and removed the <<= syntax.
    – radke
    Jan 9, 2020 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.