A simple, dependency-less, library for parsing and comparing versions according to the SemVer spec.
- Can parse any valid SemVer version.
- Has no external dependencies other than JetBrains Annotations to help document the public API.
- Very fast. Can parse 1 million versions in under 5 seconds. (2.1 seconds on my cpu, a Ryzen 5 3600.) At that level, speed is insignificant, unless you have a really weird usecase where you need to parse hundreds of thousands of versions a second.
- Simple to use API.
- Includes a set of Kotlin extensions to make development in kotlin easier and more idiomatic.
Builds can be found on Maven Central, and can be included with any build tool that supports maven.
<dependency>
<groupId>ca.solo-studios</groupId>
<artifactId>strata</artifactId>
<version>[strata version]</version>
</dependency>
The kotlin extensions can be included as follows:
<dependency>
<groupId>ca.solo-studios</groupId>
<artifactId>strata-kotlin</artifactId>
<version>[strata version]</version>
</dependency>
implementation 'ca.solo-studios:strata:[strata version]'
The kotlin extensions can be included as follows:
implementation 'ca.solo-studios:strata-kotlin:[strata version]'
implementation("ca.solo-studios:strata:[strata version]")
The kotlin extensions can be included as follows:
implementation("ca.solo-studios:strata-kotlin:[strata version]")
Note: version parsing may throw a ParseException
, which you are expected to handle. This is thrown if ever the provided version is
incorrect.
try {
Version version = Versions.parseVersion("1.2.3");
} catch (ParseException e) {
// handle version parse exception
}
or
val version = "1.2.3".toVersion()
try {
VersionRange range = Versions.parseVersionRange("[1.2.3,4.5.6)");
} catch (ParseException e) {
// handle invalid version range parse exception
}
or
val range = "[1.2.3,4.5.6)".toVersionRange()
Version version = [...]
VersionRange range = [...]
if (range.isSatisfiedBy(version)) {
// version is within range
} else {
// version is outside range
}
or
val version = [...]
val range = [...]
if (version in range)
// version is within range
else
// version is outside range