Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

friend

sbt

I have a sbt 0.10.0 project that declares a few dependencies somewhat like:

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 wish to creat a build rule to gather all the jar dependencies of "proj", so that I can symlink them to a single directory.

Thanks.

like image 418
crelbor Avatar asked Jun 28 '11 12:06

crelbor


1 Answers

Example SBT task to print full runtime classpath

Below is roughly what I'm using. The "get-jars" task is executable 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 might want to replace fullClasspath with managedClasspath.
  • This plugin defines a simple command to generate an .ensime file, and may be a useful reference.
like image 184
Kipton Barros Avatar answered Sep 18 '22 08:09

Kipton Barros