Paul Draper
Paul Draper

Reputation: 83225

How could SBT choose highest version amongst dependencies?

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.

Upvotes: 2

Views: 1515

Answers (1)

vptheron
vptheron

Reputation: 7466

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.

Upvotes: 3

Related Questions