Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell SBT to collect all my dependencies together

Tags:

scala

sbt

When building a web application SBT is able to collect all my jar dependencies into the WAR file.

Is this possible to have SBT put all the jars I depend on in my non-web application into a directory so I can easily put them onto my class path when running the app?

like image 822
Brownie Avatar asked Apr 06 '11 10:04

Brownie


People also ask

How do we specify library dependencies in sbt?

The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.

Which is the correct way to add dependencies in sbt file?

If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

What is sbt dependency management?

These tools support automatic dependency management for your project. Like in almost every build system, SBT allows you to define library dependencies which are resolved automatically, so you don't have to download and package required libraries by yourself.


1 Answers

Yes, you can put something like this in your project definition class:

val libraryJarPath = outputPath / "lib"

def collectJarsTask = {
  val jars = mainDependencies.libraries +++ mainDependencies.scalaJars
  FileUtilities.copyFlat(jars.get, libraryJarPath, log)
}

lazy val collectJars = task { collectJarsTask; None } dependsOn(compile)

and run the task via collect-jars in your SBT console. This will copy the scala-library.jar and the jars used for compilation in a directory called lib in the same directory as your classes directory.

like image 151
Moritz Avatar answered Sep 30 '22 21:09

Moritz