How setup dependency in sbt library for version like `1.0.0-M10` and above

92 Views Asked by At

I want write library, which should work with artifact "org" %% "scanamo" version 1.0.0-M10 and above, eg 1.0.0-M11, 1.0.0-RC1, 1.0.1. But version should select library's user.

I tired "org" %% "scanamo" % "1.0.+" in sbt, but it cant find any versions.

How I can setup user provided dependency in library with rule "1.0.0-M10 and above"

2

There are 2 best solutions below

1
Thilo On BEST ANSWER

There is no such feature.

As a library, you specify the version that you need. Just a single specific version.

If the library user chooses to use a different version (or another dependency pulls in a different version), the highest version will be chosen.

That higher version may or may not work with your library. If SBT thinks (according to semantic versioning rules) that the version may be incompatible it will print a warning. But it is up to the user to figure out if it will work or not.

It is a bit of a mess. Especially in Scalaland, where incompatible library updates are frequent.

How I can setup user provided dependency in library with rule "1.0.0-M10 and above"

You depend on org" %% "scanamo" % "1.0.0-M10". You hope that later versions stay compatible with it.

1
arashi01 On

Sbt uses Ivy by default under the hood for dependency resolution. Ivy supports the concept of version matchers.

Depending on your needs, something as simple as latest.milestone in place of a version number may suffice and will make sure the latest milestone is always pulled in.

eg:

"org" %% "scanamo" % "latest.milestone"

Note: sbt 1.3 uses Coursier instead of Ivy by default.

Edit: If using sbt 1.3 it seems Coursier also has similar functionality. See Coursier Version Handling.