How to exclude transitive dependencies of other subproject in multiproject builds?

萝らか妹 提交于 2019-11-28 07:31:35

This appears to work for me:

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

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

What the projectDepenendencies is doing is what sbt, by default, attempts to do. It converts any inter-project dependencies into ModuleIDs which Ivy will use during resolution. Because the Project API has no way to specify excludes currently, we bypass this automatic layer and manually declare the Ivy dependency as well.

Result:

> 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)
 ...

And the dependent project with junit/hamcrest excluded:

> 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: 
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!