3

在我的 SBT 构建中,我正在获取一个 zip 依赖项(之前使用 sbt-native-packager 插件构建),它使用bundle分类器发布在我的本地 Ivy 存储库中。

但是我需要 Ivy 存储库中的依赖路径,以便解压缩它(使用IO.unzip),将一些文件放入其中并使用 sbt-native-packager 重新打包它。

我正在使用该artifacts(...)方法来查找工件并将其添加为依赖项:

"foo" % "bar" % "1.0-SNAPSHOT" artifacts(Artifact("bar-bundle", "zip", "zip", "bundle"))

但在那之后,我有点失落......

我试图过滤掉dependencyClasspath找到它:

val bundleFile = taskKey[File]("bundle's path")

val settings = Seq(bundleFile <<= dependencyClasspath map { _ filter (_.endsWith(".zip"))})

麻烦是:我在任何类路径中都找不到 zip 依赖项......我做错了什么?

我正在使用 sbt 0.13。

4

1 回答 1

2

Zip files aren't on the classpath by default. The types of artifacts that are included are configured by classpathTypes. You can add "zip" to it with:

classpathTypes += "zip"

It will then appear on dependencyClasspath.

However, if it isn't really supposed to go on the classpath, you might pull it out of the update report directly.

bundleFile := {
   val report: UpdateReport = update.value
   val filter = artifactFilter(name = "bar-bundle", extension = "zip")
   val all: Seq[File] = report.matching(filter)
   all.headOption getOrElse error("Could not find bar-bundle")
}

See the documentation on UpdateReport for details.

于 2013-09-19T12:48:17.860 回答