Add specific directory and its content to Universal target

ifrain picture ifrain · Feb 4, 2014 · Viewed 6.9k times · Source

I am switching from maven to sbt for a Scala project I am working on. I used to work with the maven assembly plugin where you can map any directory in the workspace to a target directory in the assembly. I didn't find any equivalent in sbt-native-package, it worth provide this feature for the Universe kind.

I understood that everything that is present in the universal subdirectory is copied to the package as such, and it works like a charm, but I lack something like the following snippet.

mappings in Universal += {
  directory("my/local/dir") -> "static/dirInPackage"
}

I would like to know if there is already a way to do that, in such case, I would be happy to know how to do it, and I propose my help to commit documentation for that part if you want. If there is no way to do this kind of customization, I will be happy to propose a patch for that after having discussed specifications.

By the way, great job, your packager is working very well, thanks !

Answer

ifrain picture ifrain · Feb 10, 2014

After having discussed with the sbt-native-manager team and a first "rejected" pull request, here is the way to do this directory mapping in the build.sbt file (see pull request https://github.com/sbt/sbt-native-packager/pull/160 which provides mode detailed documentation) :

mappings in Universal <++= (packageBin in Compile, target ) map { (_, target) =>
    val dir = target / "scala-2.10" / "api"
    (dir.***) pair relativeTo(dir.getParentFile)
} 

To reduce verbosity of the above snippet, there is an issue (https://github.com/sbt/sbt-native-packager/issues/161) to propose a more human readable way to express this directory mapping:

mappings in Universal ++= allFilesRelativeTo(file(target / "scala-2.10" / "api"))