gpt4 book ai didi

scala - 如何在SBT中使用带前缀文件夹的ZIP文件

转载 作者:行者123 更新时间:2023-12-01 01:32:39 25 4
gpt4 key购买 nike

要使用简单构建工具生成发行版ZIP,您只需执行以下操作

def distPath = (
((outputPath ##) / defaultJarName) +++
mainDependencies.scalaJars
)
lazy val dist = zipTask(distPath, "dist", "distribution.zip") dependsOn (`package`) describedAs("Zips up the project.")

这会将JAR文件添加到ZIP的根目录中。如何将JAR添加到ZIP的 lib子文件夹中?

最佳答案

对于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]

他们的声明应该是不言自明的。

关于scala - 如何在SBT中使用带前缀文件夹的ZIP文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3798181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com