javascalasbtsbt-0.13

Collecting or copying dependencies in sbt 0.13


There are a few old answered questions out there about this with answers that don't work for me in sbt 0.13.

What is the easiest way to copy all of a project's runtime dependencies (jars mostly) to some given directory in sbt 0.13? Please include where any given code should be placed.

If it matters this is for exporting some classes written in Scala (a servlet filter) for use in a war (in front of a legacy java servlet).


Solution

  • By default, sbt will just compile a jar of the contents of src/main/resources, src/main/scala, and src/main/java.

    To get all the jars in one place, you can use sbt-pack or sbt-native-packager. I'll show sbt-pack here because it's very simple.

    Include the following in project/plugins.sbt:

    addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.6.5")
    

    Then include the following in build.sbt:

    packAutoSettings
    

    Then in sbt, run pack, and the jars will be copied to target/pack/lib. (This task also generates a start script in target/pack/bin/).