Search code examples
sbtsbt-native-packager

Why does mappings in Universal have no effect on what's included in tarball?


A summary of my build.sbt looks like this:

import com.github.bigtoast.sbtliquibase.LiquibasePlugin
import S3._
import com.typesafe.sbt.SbtNativePackager._
import com.typesafe.sbt.SbtNativePackager.Universal
import com.typesafe.sbt.packager.Keys._
import Path.flat

mappings in Universal ++= {
  ((baseDirectory.value / "src/main/migrations" * "*").get map { f => f -> (f.name) })
}

When I run universal:packageZipTarball I expect the files I have in src/main/migrations to appear in the final tarball. They don't.

What I see is:

a database2-0.34.0
a database2-0.34.0/lib
a database2-0.34.0/lib/com.trailhunger.database2-0.34.0.jar
a database2-0.34.0/lib/org.postgresql.postgresql-9.3-1101-jdbc4.jar
a database2-0.34.0/lib/org.scala-lang.scala-library-2.10.3.jar

Very similar code in a another project in my build works perfectly.


Solution

  • tl;dr Your build works fine for me.

    Here's the complete build.sbt to reproduce your issue:

    packageArchetype.java_application
    
    mappings in Universal ++= {
      ((sourceDirectory in Compile).value / "migrations" * "*").get.map { f => 
        f -> (f.name)
      }
    }
    

    The point to remember is to place packageArchetype.java_application before setting the keys yourself in the build as the order does matter.

    Other than the ordering, there is a small change with sourceDirectory in Compile that gives me the proper src/main directory without concatenating the paths myself.

    > show sourceDirectory
    [info] /Users/jacek/sandbox/sbt-native-packager-playground/src
    > show compile:sourceDirectory
    [info] /Users/jacek/sandbox/sbt-native-packager-playground/src/main
    

    project/build.properties

    sbt.version=0.13.6-M1
    

    project/sbt-native-packager.sbt

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

    Under src/main/migrations I have one file - migration1.txt - that gets added to the final tarball.

    > universal:packageZipTarball
    [info] Wrote /Users/jacek/sandbox/sbt-native-packager-playground/target/scala-2.10/sbt-native-packager-playground_2.10-0.1-SNAPSHOT.pom
    a sbt-native-packager-playground-0.1-SNAPSHOT
    a sbt-native-packager-playground-0.1-SNAPSHOT/lib
    a sbt-native-packager-playground-0.1-SNAPSHOT/migration1.txt
    a sbt-native-packager-playground-0.1-SNAPSHOT/lib/default.sbt-native-packager-playground-0.1-SNAPSHOT.jar
    a sbt-native-packager-playground-0.1-SNAPSHOT/lib/org.scala-lang.scala-library-2.10.4.jar
    [success] Total time: 0 s, completed Aug 9, 2014 10:17:37 PM
    

    This is the value of universal:mappings for reference:

    > show universal:mappings
    [info] Wrote /Users/jacek/sandbox/sbt-native-packager-playground/target/scala-2.10/sbt-native-packager-playground_2.10-0.1-SNAPSHOT.pom
    [info] ArrayBuffer((/Users/jacek/sandbox/sbt-native-packager-playground/target/scala-2.10/sbt-native-packager-playground_2.10-0.1-SNAPSHOT.jar,lib/default.sbt-native-packager-playground-0.1-SNAPSHOT.jar), (/Users/jacek/.sbt/boot/scala-2.10.4/lib/scala-library.jar,lib/org.scala-lang.scala-library-2.10.4.jar), (/Users/jacek/sandbox/sbt-native-packager-playground/src/main/migrations/migration1.txt,migration1.txt))
    [success] Total time: 0 s, completed Aug 9, 2014 10:16:27 PM