如何在 SBT 中使用前缀文件夹压缩文件

发布于 2024-09-24 23:23:19 字数 356 浏览 4 评论 0原文

要使用 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 子文件夹中?

To generate a distribution ZIP with Simple Build Tool one can simply do

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

This adds the JAR files into the root of the ZIP. How does one add the JARs into a lib subfolder in the ZIP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2024-10-01 23:23:19

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

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

For sbt 0.7.x:

Nothing implemented by default as far as I know. However, you can use SBT's FileUtilities.

Try playing around with the following example, which copies your artifact jar into a tmp dir, zips the dir, and deletes it. It should be straightforward to extend it to dependent libs.

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                                                                                                                                                                                                       
  }                                                                                                                                                                                                            

}                 

The following functions from FileUtilities were used above:

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]

Their declarations should be self-explanatory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文