1

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?

Stefan K.
  • 7,701
  • 6
  • 52
  • 64

1 Answers1

1

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)
Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
  • this is nice - thank you. Can I somehow specify that it should fail, if the version of `circe-literal` wasn't bound by any (transitive) dependency, e.g. if no dependency to `"org.http4s" %% "https-circe"` was specified and the latest online dependency at that point of time is resolved? – Stefan K. Mar 27 '20 at 10:35
  • @StefanK. Maybe. Ivy allows customized version managers, in which case you could actually do the work of looking up other dependencies to figure out what dependency you need or, otherwise, fail. I don't know if one can use that with sbt, though -- I saw the documentation for ant. Also, it looks like a lot of work. – Daniel C. Sobral Mar 27 '20 at 19:45