这似乎对我有用:
val someApp = project.settings(
libraryDependencies += "junit" % "junit" % "4.11"
)
val androidApp = project.dependsOn(someApp).settings(
projectDependencies := {
Seq(
(projectID in someApp).value.exclude("junit", "junit")
)
}
)
projectDepenendencies 正在做的是 sbt 默认尝试做的事情。它将任何项目间依赖关系转换为ModuleID
Ivy 将在解析期间使用的 s。由于Project
API 目前无法指定排除项,因此我们绕过这个自动层并手动声明 Ivy 依赖项。
结果:
> show someApp/update
...
[info] Update report:
...
[info] compile:
[info] org.scala-lang:scala-library:2.10.4 (): (Artifact(scala-library,jar,jar,None,List(),None,Map()),/home/jsuereth/.sbt/boot/scala-2.10.4/lib/scala-library.jar)
[info] junit:junit:4.11: (Artifact(junit,jar,jar,None,ArraySeq(master),None,Map()),/home/jsuereth/.ivy2/cache/junit/junit/jars/junit-4.11.jar)
[info] org.hamcrest:hamcrest-core:1.3: (Artifact(hamcrest-core,jar,jar,None,ArraySeq(master),None,Map()),/home/jsuereth/.ivy2/cache/org.hamcrest/hamcrest-core/jars/hamcrest-core-1.3.jar)
...
并且排除了 junit/hamcrest 的依赖项目:
> show androidApp/update
...
[info] Update report:
...
[info] compile:
[info] org.scala-lang:scala-library:2.10.4 (): (Artifact(scala-library,jar,jar,None,List(),None,Map()),/home/jsuereth/.sbt/boot/scala-2.10.4/lib/scala-library.jar)
[info] someapp:someapp_2.10:0.1-SNAPSHOT:
...