scala – 如何在SBT中使用前缀文件夹压缩文件
发布时间:2020-12-16 10:01:27 所属栏目:安全 来源:网络整理
导读:要使用Simple Build Tool生成分发ZIP,可以简单地执行 def distPath = ( ((outputPath ##) / defaultJarName) +++ mainDependencies.scalaJars)lazy val dist = zipTask(distPath,"dist","distribution.zip") dependsOn (`package`) describedAs("Zips up the
要使用Simple Build Tool生成分发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] 他们的声明应该是不言自明的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |