tags:

views:

47

answers:

1

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?

+2  A: 

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.

axel22