Scala 如何将zip依赖项复制到SBT构建中的目标目录?

Scala 如何将zip依赖项复制到SBT构建中的目标目录?,scala,sbt,Scala,Sbt,我正在从事一个SBT项目,该项目通过sat本机打包程序生成RPM。我想加入RPM的一个项目是一个ZIP文件,它是使用sat-pack插件从一个单独的项目发布的。这个ZIP文件包含许多JAR文件,以及用于调用它们的多个脚本 我在RPM项目的build.sbt中有以下内容: libraryDependencies += ("com.mycompany" %% "aputils" % "1.0.0-SNAPSHOT").artifacts(Artifact("aputils", "zip", "zip

我正在从事一个SBT项目,该项目通过
sat本机打包程序生成RPM
。我想加入RPM的一个项目是一个ZIP文件,它是使用
sat-pack
插件从一个单独的项目发布的。这个ZIP文件包含许多JAR文件,以及用于调用它们的多个脚本

我在RPM项目的
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/
。如果我修改任务以打印
更新报告中的所有文件

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,但如果必须的话,我会这样做


我最终需要在
target/
下解压ZIP文件,以便定义一个或多个
packageMapping
条目将文件拉入RPM,但这似乎很容易通过
sbt.IO执行,如果我能首先得到一个从我们的Artifactory服务器上拉下来的原始ZIP文件的引用。

这在几天后没有得到任何响应,但我会发布我经过更多尝试和错误后得到的答案

通过检查
更新报告
,我走上了正确的道路,但我没有看到其中的正确数据。我需要深入查找
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
s将.zip文件的内容放入生成的RPM中。

我必须将下一行更改为
packageBin in Compile:=((Compile中的packageBin.dependsOn(unputilstask)).值
`