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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With