Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 如何在SBT中使用前缀文件夹压缩文件_Scala_Build_Sbt - Fatal编程技术网

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

Scala 如何在SBT中使用前缀文件夹压缩文件,scala,build,sbt,Scala,Build,Sbt,要使用简单的构建工具生成分发ZIP,只需执行以下操作 def distPath = ( ((outputPath ##) / defaultJarName) +++ mainDependencies.scalaJars ) lazy val dist = zipTask(distPath, "dist", "distribution.zip") dependsOn (`package`) describedAs("Zips up the project.") 这会将JAR文件添加到ZI

要使用简单的构建工具生成分发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目录中,对目录进行压缩,然后将其删除。将其扩展到依赖lib应该很简单

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]

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

我是SBT新手,找不到FileUtilities。是被移除了还是我找错地方了?它似乎不在scaladoc时代发生变化,SBT也是如此。sbt 0.7和0.10之间发生了一些重大变化,因此上述内容可能不再有效。@Benmcann对象sbt.IO现在包含了FileUtilities中使用的方法。