How to get a list of dependency jars from sbt 0.10.0 project

I have a sbt 0.10.0 project that expresses several dependencies somewhat:

object MyBuild extends Build {
    val commonDeps = Seq("commons-httpclient" % "commons-httpclient" % "3.1",
                         "commons-lang" % "commons-lang" % "2.6")

    val buildSettings = Defaults.defaultSettings ++ Seq ( organization := "org" )

    lazy val proj = Project("proj", file("src"),
        settings = buildSettings ++ Seq(
            name                    := "projname",
            libraryDependencies     := commonDeps, ...)

    ...
}

I want to create a build rule to collect all jar dependencies on "proj" so that I can symbolically bind them to a single directory.

Thank.

+5
source share
1 answer

Example SBT task to print the full path to the runtime

Below is roughly what I use. The get-jars task is executed from the SBT prompt.

import sbt._
import Keys._
object MyBuild extends Build {
  // ...
  val getJars = TaskKey[Unit]("get-jars")
  val getJarsTask = getJars <<= (target, fullClasspath in Runtime) map { (target, cp) =>
    println("Target path is: "+target)
    println("Full classpath is: "+cp.map(_.data).mkString(":"))
  }
  lazy val project = Project (
    "project",
    file ("."),
    settings = Defaults.defaultSettings ++ Seq(getJarsTask)
  )
}

Other resources

  • Unofficial guide to sbt 0.10.
  • Keys.scala defines predefined keys. For example, you can replace fullClasspathwith managedClasspath.
  • .ensime .
+8

All Articles