erp12.fijit.version
A suite of functions and macros to help write Clojure code that is agnostic to the version of Scala on the classpath.
by-scala-version
macro
(by-scala-version & versions-and-forms)
Macro that executes an appropriate form depending on the version of the Scala language found on the classpath.
The arguments should be alternating between a version keyword and a form. Version keywords can either take the form :major.minor
or :major.minor.patch. For example
:2.13and
:2.12.6` are valid version keywords.
The form that corresponds to the highest compatible version will be executed. A compatible version is one that has the same major and minor versions as the current version of Scala on the classpath. If a form’s version keyword contains a patch version, it will only be valid if the patch version of the active Scala version is at least the same number.
(by-scala-version :2.12 :A
:2.12.10 :B
:2.13.4 :C)
For example the above code will
- Return
:A
on Scala 2.12.0 through 2.13.9. - Return
:B
for :2.12.10 and all other 2.12.x versions. - Throw and exception for scala 2.13.0 through 2.13.3.
- Return
:C
for 2.13.4 and all other 2.13.x versions.
compare-versions
(compare-versions v1 v2)
Given 2 version map describing versions, return -1 or 1 if v1
is lower or higher than v2
. Returns 0 if the versions are logically the same.
Examples:
(compare-versions {:major 2 :minor 12 :patch 13} {:major 2 :minor 13}) ;; => -1
(compare-versions {:major 2 :minor 13 :patch 6} {:major 2 :minor 13}) ;; => 1
(compare-versions {:major 2} {:major 2 :minor 0}) ;; => 0
parse-version
(parse-version version-keyword)
Given a version keyword, parse it into a map with the keys :major
, :minor
, and :patch
and numeric values.
Examples:
(parse-version :2.12) ; => {:major 2 :minor 12}
(parse-version :2.13.6) ; => {:major 2 :minor 13 :patch 6}
scala-version
A map describing the version of the Scala language that is currently on the classpath. Composed of 3 integer fields under the keys :major
, :minor
, and :patch
.