SBT: describe external dependency relative to another (transitive) dependency?

86 Views Asked by At

To avoid jar hell, I'd like to refer to a dependency relatively.

For example, when I add a dependency to "org.http4s" %% "https-circe" % "0.21.1":

cs resolve org.http4s:http4s-circe_2.12:0.21.1 | grep -i circe                                                                                ⎈ eks-cluster-eu-west-1-dev/master
io.circe:circe-core_2.12:0.13.0:default

I'd like to add a dependency to "circe-literal" in the version, which was automatically resolved by SBT's mediator. In this example "0.13.0". Is this possible?

1

There are 1 best solutions below

2
On

On one hand, you could add circe-literal with a wildcard version, and using the latest-compatible conflict manager would get a version of it that is compatible with circe-core. Sadly, one cannot, without resorting to the coursier plugin, specify conflict managers for a specific artifact.

If that is ok, with you, however, you should be able to specify this:

conflictManager := ConflictManager.latestCompatible
libraryDependencies += "io.circe" %% "circe-literal % "[0,)"

You'll have to use the ivy resolver to get that working, though.

dependencyResolution := sbt.librarymanagement.ivy.IvyDependencyResolution(ivyConfiguration.value)

Using that, I got exactly what you wanted:

[info]  [SUCCESSFUL ] io.circe#circe-literal_2.12;0.13.0!circe-literal_2.12.jar (304ms)