Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the naming structure of the dependent libraries in the zip produced by sbt-native-packager?

I am using the Universal plugin of the sbt-native-packager to create a zip package. I am using the below setting for creating a default structure:

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

enablePlugins(JavaAppPackaging)

Currently all my project dependencies in the zip fall under the lib folder e.g.

lib/
    ch.qos.logback.logback-classic-1.1.3.jar
    dom4j.dom4j-1.6.1.jar

How do I change the name of all the libraries to contain only the artifactId and version of the jar and not the complete name. For example, for the above, I want something like this:

lib/
    logback-classic-1.1.3.jar
    dom4j-1.6.1.jar
like image 864
Abhinav Avatar asked Oct 15 '25 19:10

Abhinav


1 Answers

The logic for this is hard coded in the JavaAppPackaging archetype. However you can remap your library dependencies.

mappings in Universal := (mappings in Universal).value.map {
  case (file, dest) if dest.startsWith("lib/") =>
        file -> changeDestination(dest)
  case mapping => mapping
}

def changeDestination(dest: String): String = ???

Next you need to change the scriptClasspathOrdering which is responsible for the app_classpath defined in the BashStartScriptPlugin.

scriptClasspathOrdering := scriptClasspathOrdering.value.map {
   case (file, dest) if dest.startsWith("lib/") =>
         file -> changeDestination(dest)
   case mapping => mapping
}

The destination folder should be lib/ as the bash script assumes this.

Note that I have not tested this as this is a very uncommon use case. However the main idea should be clear :)

cheers, Muki

like image 111
Muki Avatar answered Oct 18 '25 14:10

Muki