如何在多项目构建中排除其他子项目的传递依赖关系?

时间:2014-07-30 11:31:05

标签: android scala sbt sbt-0.13

Build.scala中,项目之间存在依赖关系:

val coreLib = Projects.coreLib()
val consoleApp = Projects.consoleApp().dependsOn(coreLib)
val androidApp = Projects.androidProject().dependsOn(coreLib/*, exclusions = xpp */)

核心库项目在其libraryDependencies(XPP解析器)中定义了一个库,我想在androidApp中排除它,因为Android框架有自己开箱即用的XP​​P实现。

如何从coreLib项目中androidApp的传递依赖项中排除XPP库?

编辑:

根据我的研究,排除仅适用于与ModuleID一起使用的libraryDependency。同时dependsOn将所有传递依赖项放到classpath中,api无法排除此项目的某些传递依赖项,dependsOn

详情:

我目前正在运行sbt 0.13.5。

commonLib的

libraryDependencies以及build.sbt中提供的各种设置,以便此项目可以作为独立项重用,并且因为它感觉sbt中提供设置的权利和自然方式。< / p>

1 个答案:

答案 0 :(得分:33)

这似乎对我有用:

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 s,Ivy将在解析期间使用它们。由于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: 
...