反正是有prePEND在SBT一个罐子到unmanagedClasspath [英] Is there anyway to prepend a jar to the unmanagedClasspath in sbt
问题描述
我使用的是Android的SBT-插件的SBT,我想非托管jar添加到测试类路径中。究其原因是含有的android.jar为例外org.json库和结果被抛出的单元测试存根功能。这是我在做什么。
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.json libraries and results in exceptions being thrown for unit tests. This is what I am doing
unmanagedClasspath in Test <+= (baseDirectory) map { base =>
Attributed.blank(base/"test-libs"/"json.jar")
}
由于这个文件会被忽略的罐子,当我在SBT内运行测试命令中的顺序。如果我键入命令的顺序清晰地显示的android.jar作为第一个罐子
Because of the order of the jars this file is ignored during when i run the test command within the sbt. If I type the command the order clearly shows the android.jar as the first jar
显示测试:非托管类路径
[信息] ArrayBuffer(归因(/家/罗希特/项目/ Android的SDK-Linux的/平台/ android- 17 /的android.jar),归因(/家/罗希特/项目/ barfrendz /主干/ src目录/ buzze /测试 - 库/ json.jar))
show test:unmanaged-classpath [info] ArrayBuffer(Attributed(/home/rohit/Projects/android-sdk-linux/platforms/android- 17/android.jar), Attributed(/home/rohit/Projects/barfrendz/trunk/src/buzze/test-libs/json.jar))
如果我创建一个lib文件夹,让SBT拿起罐子JSON的顺序是相反的测试现在运行,但我再也不能因与该的android.jar空间org.json冲突造成Android包。这里是个例外
If I create a lib folder and let sbt pick up the json jar the order is reversed the tests now run, but I can no longer create an android package due to conflicts with the org.json namespace in android.jar. Here is the exception
[error] (Buzze/android:proguard) java.io.IOException: Can't read [/home/rohit/Projects/barfrendz/trunk/src/buzze/lib/json.jar(;;;;!META-INF/MANIFEST.MF,!**/R.class,!**/R$*.class,!**/TR.class,!**/TR$.class,!**/library.properties)] (Can't process class [org/json/CDL.class] (Unsupported version number [51.0] for class format))
反正我有可以改变罐子的顺序的类路径中的单元测试
Is there anyway I can change the order of the jars in the classpath for the unit tests
推荐答案
1 + =
,使用&LT;&LT; =
,GET unmanagedClasspath
本身作为一个依赖,然后根据需要进行修改。该文档有这样一个例子, 解析器
:
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 =>
val localMaven = "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
localMaven +: rs
}
这样, localMaven
在解析器先结束
。
按照 API文档中, unmanagedClasspath
是一种类型的工作
类路径
。请注意,当您使用语法,要更改的类路径
,而不是工作
。
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
.
有关类路径的API文档是这里 - 这是一个键入
,它指向顺序[归因[文件]
,这样你就可以对其进行操作与任何 SEQ
命令。我在这里尝试了代码段和它的作品:
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 in Test <<= (unmanagedClasspath in Test, 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] Total time: 0 s, completed 30/08/2013 13:32:42
>
这篇关于反正是有prePEND在SBT一个罐子到unmanagedClasspath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!