Search code examples
sbtsbt-native-packager

sbt modify the lib output directory when using sbt-native-packager


How can I modify the output of the final packaged zip to move the "lib" directory contents up one level. Basically I output a zip and the contents are like so:

ZIP FILE CONTENT:
-- my-plugin-1.0.jar
-- /lib
    -- /lib/mydependency1.jar
    -- /lib/mydependency2.jar

 ZIP FILE CONTENT I WISH TO HAVE:
 -- my-plugin-1.0.jar
 -- mydependency1.jar
 -- mydependency2.jar

I want to move everything in "lib" up one level to the root output.

sbt version 0.13.0

Here is my build.sbt:

import NativePackagerHelper._

organization := "com.company.product"
name := "my-plugin"
version := "1.0"
enablePlugins(UniversalPlugin)
packageName in Universal:= "deployment"
publishArtifact in (Compile, packageDoc) := false
artifactName := {
    (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
        artifact.name + "-" + module.revision + "." + artifact.extension
}
javacOptions ++= Seq("-source", "1.8")
mappings in Universal <+= packageBin in Compile map { jar => jar -> (jar.getName()) }
topLevelDirectory := None

plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0")

command line:

sbt universal:packageBin

Solution

  • Looks like your requirement is a first class citizen in sbt-native-packager:

    mappings in Universal ++= contentOf("src/main/resources/cache")