Hi, our team is currently trying to setup a proper versioning scheme for stable / snapshot jars. It’s probably based on ‘git describe’ which gives sth. like:
2.0.0-1-5f26284a
This is the last stable (tagged) version, plus the number of commits since then and the latest commit SHA. On the other hand, we’d like to stick to semver as close as possible. Something like:
2.0.0+5f26284a.1
I was trying to find a clear spec. on how gradle compares version strings (in terms of precedence) but did not find much. Particularly interesting are the resolution defs:
‘+’
‘2.+’
‘2.0.0+’
Does the ‘-’ sign indicate negative precedence (i.e. snapshots)? And does the ‘+’ sign indicate metadata as in semver?
A version selector containing ‘+’ will match any version that starts with the characters preceding the ‘+’, and will resolve to the highest such version. There isn’t currently a spec for how Gradle matches and orders version numbers, but the algorithm was ported over unchanged from Ivy, so perhaps you’ll find something in the Ivy docs. Alternatively, you could check out the code or run some experiments. From what I remember, version parts following after the dotted parts are compared lexicographically, apart from a few appendices such as ‘-rc’ that are treated specially. If the current algorithm is ever changed, I’d expect that you’ll have the opportunity to plug in your own version matcher/comparator instead.
Thank you for the info. I dug into the source code and found ivyservice/ivyresolve/strategy/StaticVersionComparator.java. I assume that this comparator is used for both comparing between the selector from the build script and a version and between two different available versions in the repo.
A few test results:
1.0 < 1.0.0
1.0 > 1.0-SNAPSHOT+1024
1.0 > 1.0-SNAPSHOT
1.0 > 1.0-final
1.0.0 > 1.0-final
1.0-A < 1.0-final
1.0-A < 1.0-rc
1.0-A > 1.0-dev
1.0+a > 1.0+A
1+0+SNAPSHOT+1024 == 1.0-SNAPSHOT.1024
What I learned from that and the code:
The classifiers ‘dev’, ‘rc’ and ‘final’ are retreated as special values (case-insensitive) * Dot, plus and minus are treated equally. * If A has more parts than B, then A is preferred iff it ends with a number, B otherwise * In general, numbers have higher precedence than text (except special values ‘rc’ and ‘final’) * Text is compared case-sensitive (!!) with US locale