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

dan*_*nt3 20 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 */)
Run Code Online (Sandbox Code Playgroud)

核心库项目在其libraryDependencies(XPP解析器)中定义了一个库,我希望将其排除在外androidApp,因为Android框架具有开箱即用的自己的XPP实现.

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

编辑:

根据我的研究,排除仅可能ModuleID与之结合使用libraryDependency.同时dependsOn将所有传递依赖项放到classpath中,api中没有办法排除这个项目的一些传递依赖项,你dependsOn

细节:

我目前正在运行0.13.5.

libraryDependenciescommonLib以及build.sbt中提供的各种设置,以便该项目可以作为独立的方式重用,并且因为它感觉正确且自然地提供设置sbt.

jsu*_*eth 34

这似乎对我有用:

val someApp = project.settings(
  libraryDependencies += "junit" % "junit" % "4.11"
)

val androidApp = project.dependsOn(someApp).settings(
  projectDependencies := {
    Seq(
      (projectID in someApp).value.exclude("junit", "junit")
    )
  }
)
Run Code Online (Sandbox Code Playgroud)

projectDepenendencies正在做的是默认情况下sbt尝试做什么.它将任何项目间依赖项转换为ModuleIDIvy将在解析期间使用的s.由于ProjectAPI无法指定当前的排除,我们绕过此自动图层并手动声明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)
 ...
Run Code Online (Sandbox Code Playgroud)

并且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: 
...
Run Code Online (Sandbox Code Playgroud)

  • 这应该在SBT文件中.确认这也适用于SBT 0.13.7. (4认同)