how do I get sbt to gather all the jar files my code depends on into one place?
Solution 1
There are many plugins you can use: sbt-assembly, sbt-proguard, sbt-onejar, xitrum-package etc.
See the list of SBT plugins.
Solution 2
Add the following line to your build.sbt
file.
retrieveManaged := true
This will gather the dependencies locally
Solution 3
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
Solution 4
Try sbt-pack plugin https://github.com/xerial/sbt-pack, which collects all dependent jars in target/pack folder and also generates launch scripts.
Solution 5
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.
Tim Pigden
Updated on January 31, 2020Comments
-
Tim Pigden over 4 years
I'm new to sbt. 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?