Tim Pigden
Tim Pigden

Reputation: 925

how do I get sbt to gather all the jar files my code depends on into one place?

I'm new to . I want it to put all the dependency jar files as well as my jar file into one place. SBT will run the app, but I've got various dependencies scattered around and an .ivy folder full of things my jar file depends on indirectly.

So Is there a simple command to copy them all into a single place so I can distribute it to another machine?

Upvotes: 37

Views: 27763

Answers (7)

CatsLoveJazz
CatsLoveJazz

Reputation: 869

Add the following line to your build.sbt file.

retrieveManaged := true

This will gather the dependencies locally

Upvotes: 14

anvie
anvie

Reputation: 41

May you looking for this sbt plugin: https://github.com/anvie/sbt-onedir-plugin

Upvotes: 0

pr1001
pr1001

Reputation: 21962

There are many plugins you can use: sbt-assembly, sbt-proguard, sbt-onejar, xitrum-package etc.

See the list of SBT plugins.

Upvotes: 19

Adrien Aubel
Adrien Aubel

Reputation: 692

You could also try SBT Native Packager: https://github.com/sbt/sbt-native-packager (sbt 0.7+)

This is still a WIP but will be used in Play Framework 2.2 in the coming weeks. With this, you can create standalone ZIP files, Debian packages (DEB), Windows installation packages (MSI), DMG, RPM, and so on.

Upvotes: 4

leo
leo

Reputation: 161

Try sbt-pack plugin https://github.com/xerial/sbt-pack, which collects all dependent jars in target/pack folder and also generates launch scripts.

Upvotes: 8

bstpierre
bstpierre

Reputation: 31176

The SBT docs have a list of "One Jar Plugins":

Upvotes: 2

torrens
torrens

Reputation: 163

Create a task in your build file like this:

lazy val copyDependencies = TaskKey[Unit]("pack")

def copyDepTask = copyDependencies <<= (update, crossTarget, scalaVersion) map {
  (updateReport, out, scalaVer) =>
    updateReport.allFiles foreach {
      srcPath =>
        val destPath = out / "lib" / srcPath.getName
        IO.copyFile(srcPath, destPath, preserveLastModified = true)
    }
}

Add the Task to a Project like this:

lazy val HubSensors =
  Project("HubSensors", file("HubSensors"), settings = shared ++ Seq(
    copyDepTask,
    resolvers ++= Seq(novusRels),
    libraryDependencies ++= Seq(
      jodatime
    )
  )) dependsOn(HubCameraVision, JamServiceProxy, HubDAL)

In the SBT console type:

project [Project Name]
pack

Upvotes: 11

Related Questions