How could SBT choose highest version amongst dependencies?

大兔子大兔子 提交于 2020-01-02 10:23:40

问题


This is a question about versioning and workflow.

I have multiple projects

projectA/build.sbt

version := "1.0.0"
libraryDependencies ++= Seq(
  "com.example" % "projectB" % "1.0.0",
  "com.example" % "util" % "1.0.0"
)

projectB/build.sbt

version := "1.0.0"
libraryDependencies ++= Seq(
  "com.example" % "util" % "1.0.0"
)

util/build.sbt

version := "1.0.0"

------------------------ DEVELOPMENT ------------------------

I added a method in util.

util/build.sbt

version := "2.0.0"

This added functionality is great, so I use it to optimize projectB.

projectB/build.sbt

version := "1.1.0"
libraryDependencies ++= Seq(
  "com.example" % "util" % "2.0.0"
)

------------------------ DEVELOPMENT ------------------------

I want projectA to be faster, so I pull in projectB.

projectA/build.sbt

version := "1.1.0"
libraryDependencies ++= Seq(
  "com.example" % "projectB" % "1.1.0",
  "com.example" % "util" % "1.0.0"
)

------------------------ PROBLEM ------------------------

Now, projectA requires util version 1.0.0, but project B requires util version 2.0.0.

I can update projectA to use the new version of util. The issue is that the number of projects and dependencies I need to update can be be very large, and the chain of dependencies can be very long. (Imagine projectZ which depends on projectA and util.)

Is there a way that I can have my project dependencies have a minimum version?

For example, if projectA needs util version 1.0.0 and projectB needs util version 2.0.0, projectA will wind up using the 2.0.0 version.

If so, what would happen in this case if there were version 3.0.0 of util available? Would projectA wind up using 2.0.0, or 3.0.0?

For me, it would be ideal if I could have a project use the greatest version, from among its own dependencies and (recursively) its dependents' dependencies, but no higher than that.


回答1:


For me, it would be ideal if I could have a project use the greatest version, from among its own dependencies and (recursively) its dependents' dependencies, but no higher than that.

From the Sbt documentation http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management.html#conflict-management :

The conflict manager decides what to do when dependency resolution brings in different versions of the same library. By default, the latest revision is selected.

This is already the default behavior.

The same documentation explains how to force version, specify minimum version, etc.



来源:https://stackoverflow.com/questions/21442245/how-could-sbt-choose-highest-version-amongst-dependencies

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