对于 sbt 0.7.x:
据我所知,默认情况下没有任何实现。但是,您可以使用 SBT 的 FileUtilities。
尝试使用以下示例,它将您的工件 jar 复制到 tmp 目录中,压缩该目录并将其删除。将其扩展到依赖库应该很简单。
class project(info: ProjectInfo) extends DefaultProject(info) {
def distPath = {
((outputPath ##) / defaultJarName) +++ mainDependencies.scalaJars
}
private def str2path(str: String): Path = str
lazy val dist = task {
FileUtilities.copyFile((outputPath ##) / defaultJarName, "tmp" / "lib" / defaultJarName, log)
FileUtilities.zip(List(str2path("tmp")), "dist.zip", true, log)
FileUtilities.clean("tmp", log)
None
}
}
上面使用了以下函数FileUtilities
:
def zip(sources: Iterable[Path], outputZip: Path, recursive: Boolean, log: Logger)
def copyFile(sourceFile: Path, targetFile: Path, log: Logger): Option[String]
def clean(file: Path, log: Logger): Option[String]
他们的声明应该是不言自明的。