How to zip files with a prefix folder in SBT

To create a ZIP distribution using the Simple Build Tool, you 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 to the zip root. How to add JAR to lib subfolder in ZIP?

+4
source share
1 answer

For sbt 0.7.x:

By default, as far as I know, nothing is implemented. However, you can use the SBT FileUtilities utilities.

Try playing with the following example, which will copy your artifact jar into the tmp directory, zip up the directory and delete it. It should be simple to extend it to dependent libraries.

 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 clear.

+4
source

All Articles