Skip to content Skip to sidebar Skip to footer

Is There Anyway To Prepend A Jar To The Unmanagedclasspath In Sbt

I am using the android-sbt-plugin with the sbt, and I would like to add an unmanaged jar to the test classpath. The reason being android.jar contains stub functions for the org.jso

Solution 1:

Instead of using <+=, use <<=, get unmanagedClasspath itself as a dependency, and then modify it as desired. The documentation has such an example with resolvers:

resolvers <<= resolvers {rs =>
  vallocalMaven="Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
  localMaven +: rs
}

This way, localMaven ends up first in resolvers.

According to the API docs, the unmanagedClasspath is a Task of type Classpath. Note that when you use that syntax, you are changing the Classpath, not the Task.

The API doc for the classpath is here -- it's a type, and it points to Seq[Attributed[File]], so you can manipulate it with any Seq command. I tried out the snippet here and it works:

$ cat build.sbt
unmanagedClasspath inTest <<= (unmanagedClasspath inTest, baseDirectory) map { (uc, base) =>Attributed.blank(base/"test-libs"/"json.jar") +: uc
}

Daniel@DANIEL-PC /c/scala/Programas/sbtTest
$ sbt
[info] Set current project to default-60c6f9 (in build file:/C:/scala/Programas/sbtTest/)
> show test:unmanaged-classpath
[info] ArrayBuffer(Attributed(C:\scala\Programas\sbtTest\test-libs\json.jar))
[success] Totaltime: 0 s, completed 30/08/201313:32:42
>

Solution 2:

Maybe overriding the unmanagedJars instead of the unmanagedClasspath would allow you to do this:

http://www.scala-sbt.org/0.12.3/docs/Detailed-Topics/Library-Management.html

Post a Comment for "Is There Anyway To Prepend A Jar To The Unmanagedclasspath In Sbt"