How do I change universal zip file name using sbt-native-packager

*爱你&永不变心* 提交于 2019-12-23 12:08:44

问题


I am using:

  • scala 2.10.3
  • sbt 13.2

with plugin:

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.3")

I am using the universal:packgeBin to generate the universal zip file and publish to ivy repository. I'd like to change the zip file name from project_id_scalaversion_buildVersion.zip to project_id_scalaversion_buildVersion_dist.zip. How would I do that?


回答1:


This answer is based on version 1.0.3 that I have used, but it should apply to the latest version (1.1.5) as well.

You can name your package however you want. The only thing to do is to add the following setting to the configuration of your project:

packageName in Universal := s"${name.value}_${scalaVersion.value}_${version.value}_dist"



回答2:


I think you cannot change the name of the generated artifact just for the universal:packageBin easily.

You can change the name of the generated artifact globally, by using artifactName.

artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
  artifact.name + module.revision + "_dist." + artifact.extension
}

This will however also modify also the name of the generated jar file, and perhaps some other names of the generated artifacts.

If you wanted to change the name only of the file generated by the universal:packageBin you could rename the file after it was generated. Sbt gives you utilities which make this rather easy.

packageBin in Universal := {
  val originalFileName = (packageBin in Universal).value
  val (base, ext) = originalFileName.baseAndExt
  val newFileName = file(originalFileName.getParent) / (base + "_dist." + ext)
  IO.move(originalFileName, newFileName)
  newFileName
}

Now invoking the universal:packageBin should execute your new task, which will rename the file after it's created.



来源:https://stackoverflow.com/questions/24899453/how-do-i-change-universal-zip-file-name-using-sbt-native-packager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!