How to add banks from more than one unmanaged directory to the SBT.scala project configuration

I am trying to get SBT to create a project that can contain more than one unmanaged directory. If I had a single directory, I could easily do this as follows:

unmanagedBase := file( "custom-libs" ).getAbsoluteFile

But since I have two directories with unmanaged banks, I need to be able to add them all. I found some information here , but still doesn't seem useful for my complete .scala build .

I created a simple project that shows the problem here . Below is my Build.scala file .

UPDATE

I got some help on the sbt-users list and was able to identify unmanaged jars correctly, but the code still does not compile (but sbt show unmanaged-jars shows the files correctly).

import sbt._
import com.github.siasia._
import PluginKeys._
import Keys._

object Build extends sbt.Build {

  import Dependencies._

  val unmanagedListing = unmanagedJars :=  {
    Dependencies.listUnmanaged( file(".").getAbsoluteFile )
  }

  lazy val myProject = Project("spray-template", file("."))
    .settings(WebPlugin.webSettings: _*)
    .settings(port in config("container")  := 8080)
    .settings(
      organization  := "com.example",
      version       := "0.9.0-RC1",
      scalaVersion  := "2.9.1",
      scalacOptions := Seq("-deprecation", "-encoding", "utf8"),
      resolvers     ++= Dependencies.resolutionRepos,
      libraryDependencies ++= Seq(
        Compile.akkaActor,
        Compile.sprayServer,
        Test.specs2,
        Container.jettyWebApp,
        Container.akkaSlf4j,
        Container.slf4j,
        Container.logback
      ),
      unmanagedListing
    )

}

object Dependencies {
  val resolutionRepos = Seq(
    ScalaToolsSnapshots,
    "Typesafe repo" at "http://repo.typesafe.com/typesafe/releases/",
    "spray repo" at "http://repo.spray.cc/"
  )

  def listUnmanaged( base : RichFile ) : Keys.Classpath = {
    val baseDirectories = (base / "custom-libs") +++ ( base / "custom-libs2" )
    (baseDirectories ** "*.jar").classpath
  }

  object V {
    val akka    = "1.3"
    val spray   = "0.9.0-RC1"
    val specs2  = "1.7.1"
    val jetty   = "8.1.0.v20120127"
    val slf4j   = "1.6.4"
    val logback = "1.0.0"
  }

  object Compile {
    val akkaActor   = "se.scalablesolutions.akka" %  "akka-actor"      % V.akka    % "compile"
    val sprayServer = "cc.spray"                  %  "spray-server"    % V.spray   % "compile"
  }

  object Test {
    val specs2      = "org.specs2"                %% "specs2"          % V.specs2  % "test"
  }

  object Container {
    val jettyWebApp = "org.eclipse.jetty"         %  "jetty-webapp"    % V.jetty   % "container"
    val akkaSlf4j   = "se.scalablesolutions.akka" %  "akka-slf4j"      % V.akka
    val slf4j       = "org.slf4j"                 %  "slf4j-api"       % V.slf4j
    val logback     = "ch.qos.logback"            %  "logback-classic" % V.logback
  }
}
+5
source share
4 answers

As Eugene Vigdorchik answered , which made him work as the following code:

import sbt._
import com.github.siasia._
import PluginKeys._
import Keys._

object Build extends sbt.Build {

  import Dependencies._

  var unmanagedListing = unmanagedJars in Compile :=  {
    Dependencies.listUnmanaged( file(".").getAbsoluteFile )
  }

  lazy val myProject = Project("spray-template", file("."))
    .settings(WebPlugin.webSettings: _*)
    .settings(port in config("container")  := 8080)
    .settings(
      organization  := "com.example",
      version       := "0.9.0-RC1",
      scalaVersion  := "2.9.1",
      scalacOptions := Seq("-deprecation", "-encoding", "utf8"),
      resolvers     ++= Dependencies.resolutionRepos,
      libraryDependencies ++= Seq(
        C.akkaActor,
        C.sprayServer,
        Test.specs2,
        Container.jettyWebApp,
        Container.akkaSlf4j,
        Container.slf4j,
        Container.logback
      ),
      unmanagedListing
    )

}

object Dependencies {
  val resolutionRepos = Seq(
    ScalaToolsSnapshots,
    "Typesafe repo" at "http://repo.typesafe.com/typesafe/releases/",
    "spray repo" at "http://repo.spray.cc/"
  )

  def listUnmanaged( base : RichFile ) : Keys.Classpath = {
    val baseDirectories = (base / "custom-libs") +++ ( base / "custom-libs2" )
    (baseDirectories ** "*.jar").classpath
  }

  object V {
    val akka    = "1.3"
    val spray   = "0.9.0-RC1"
    val specs2  = "1.7.1"
    val jetty   = "8.1.0.v20120127"
    val slf4j   = "1.6.4"
    val logback = "1.0.0"
  }

  object C {
    val akkaActor   = "se.scalablesolutions.akka" %  "akka-actor"      % V.akka    % "compile"
    val sprayServer = "cc.spray"                  %  "spray-server"    % V.spray   % "compile"
  }

  object Test {
    val specs2      = "org.specs2"                %% "specs2"          % V.specs2  % "test"
  }

  object Container {
    val jettyWebApp = "org.eclipse.jetty"         %  "jetty-webapp"    % V.jetty   % "container"
    val akkaSlf4j   = "se.scalablesolutions.akka" %  "akka-slf4j"      % V.akka
    val slf4j       = "org.slf4j"                 %  "slf4j-api"       % V.slf4j
    val logback     = "ch.qos.logback"            %  "logback-classic" % V.logback
  }
}

A repo source with a complete example is available on Github .

+2
source

I just posted a snippet from my file build.sbtusing sbt 0.11.x . It could probably be reorganized a bit.

unmanagedJars in Compile <++= baseDirectory map { base =>
    val libs = base / "lib"
    val dirs = (libs / "batik") +++ (libs / "libtw") +++ (libs / "kiama")
    (dirs ** "*.jar").classpath
}
+7
source

You can add additional paths to the list of folders for scanning unmanaged dependencies. For example, to look in a folder named "config" in addition to "lib" for a task run, you can add the following. To change the task compile Runtime- compile.

unmanagedClasspath in Runtime <+= (baseDirectory) map {
  bd => Attributed.blank(bd / "config")
}
+3
source

Here's a general solution for recursively loading unmanaged JARs (for sbt 0.13.x): fooobar.com/questions/1103427 / ...

-1
source

All Articles