簡體   English   中英

如何將zip依賴項復制到SBT構建中的目標目錄?

[英]How do I copy a zip dependency to the target directory in an SBT build?

我正在研究一個通過sat-native-packager生成RPM的SBT項目。 我要拉入RPM的項目之一是ZIP文件,該文件是使用sat-pack插件從單獨的項目發布的。 該ZIP文件包含許多JAR文件,以及用於調用它們的多個腳本。

我在RPM項目的build.sbt具有以下build.sbt

libraryDependencies += ("com.mycompany" %% "aputils" % "1.0.0-SNAPSHOT").artifacts(Artifact("aputils", "zip", "zip"))

// Task to download and unpack the utils bundle
lazy val unpackUtilsTask = taskKey[Unit]("Download the utils bundle to the target directory")
unpackUtilsTask := {
  val log = streams.value.log
  val report: UpdateReport = (update in Rpm).value
  val filter = artifactFilter(extension = "zip")
  val matches: Seq[File] = report.matching(filter)
  matches.foreach{ f =>
    log.info(s"Filter match: ${f}")
    IO.copyFile(f, target.value)
  }
}

當我運行此任務時,它與UpdateReport中的任何條目都不匹配。 沒有打印任何內容,也沒有文件復制到target/ 如果我修改任務以改為打印UpdateReport中的所有文件:

report.allFiles.foreach(f => log.info(s"All files: $f))

我看到了許多JAR文件,但沒有看到我的ZIP文件。 JAR文件原來是ZIP文件中包含的所有JAR文件。 我不確定為什么要解壓縮ZIP並將其內容列出為像這樣的依賴項。 如果我將依賴項標記為notTransitive ,則報告中不會列出所包含的JAR,但是ZIP也不包括在內。

該項目正在使用SBT 0.13.15。 我希望此時不將其更新為1.x,但是如果需要的話,我會這樣做。

我最終需要將ZIP文件解壓縮到target/下,以便我可以定義一個或多個packageMapping條目以將文件拉入RPM,但這似乎很容易通過sbt.IO ,如果我可以先獲得對從我們的Artifactory服務器提取的原始ZIP文件。

幾天后沒有得到任何答復,但是我將發布經過更多的嘗試和錯誤后能夠提出的答案。

通過檢查UpdateReport ,我處在正確的軌道上,但是我沒有在其中查看正確的數據。 我需要深入查找以找到ModuleReport ,該模塊可以顯示.zip文件在構建計算機上的下載位置。 一旦有了該路徑,就可以使用IO.unzip()將其解壓縮到target/ 這是我的任務最終的外觀:

libraryDependencies += ("com.mycompany" %% "aputils" % "1.0.0-SNAPSHOT").artifacts(Artifact("aputils", "zip", "zip"))

// Task to unzip the utils ZIP file to the target directory so we can define a package mapping
lazy val unpackUtilsTask = taskKey[Unit]("Download the utils bundle to the target directory")
unpackUtilsTask := {
  val log = streams.value.log
  val cReport: ConfigurationReport = (update in Compile).value.configuration("compile").get
  cReport.modules.foreach{ mReport =>
    if (mReport.module.name.startsWith("aputils")) {
      mReport.artifacts.foreach{ case (art, f) =>
        log.info(s"Unpacking aputils bundle: ${f.getAbsolutePath}")
        IO.unzip(f, target.value)
      }
    }
  }
}
packageBin in Rpm := ((packageBin in Rpm).dependsOn(unpackUtilsTask)).value

最后一行將任務附加到構建RPM的任務,因此將在構建RPM之前將其解壓縮,並且我們可以定義packageMapping來將.zip文件的內容放入生成的RPM中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM