This is Fabric's library for parsing, interpreting and comparing version strings, as well as version ranges. While it's first-and-foremost targeted at working with Semantic Versioning compatible strings, it also has a powerful fallback mode for comparing non-semver versions, using the FlexVer library.
Fabric SemVer has been split off from Fabric Loader, where the code was originally developed at. For backwards compatibility purposes, the package structure hasn't been altered since, though beware that this may change in the future.
- Parse versions via
Version.parse(versionString)
. - Compare versions against each other via
versionA.compareTo(versionB)
. IfversionA
is older thanversionB
, the returned int is negative; if they're the same, it's zero; otherwise a positive int gets returned. - Running
SemanticVersion.parse(versionString)
directly can yield aVersionParsingException
, if the passed string isn't SemVer compliant. A safer approach would be to parse the version normally (see above) and check viaversion instanceof SemanticVersion
if it could indeed be represented as a semantic version. - Access parsed
SemanticVersion
metadata viaversion.getVersionComponent(position)
,version.getPrereleaseKey()
etc. See the SemanticVersion interface for more details. - Parse version predicates (can be used for version ranges) via
VersionPredicate.parse(predicateString)
. predicate.test(version)
checks whether the passed version satisfies the given predicate.
For more information, please check the Javadoc comments.
Fabric SemVer implements a superset of vanilla Semantic Versioning. This superset allows additionally:
- Arbitrary number of version core components, but at least 1.
x
,X
or*
for the last version core component.- Arbitrary build metadata.
To use this library in your project, simply add the following dependency to your build.gradle
file:
repositories {
maven {
url = "https://maven.fabricmc.net"
name = "FabricMC"
}
}
dependencies {
api 'net.fabricmc:fabric-semver:<VERSION>'
}
If you want to depend on the fat JAR ("uberjar"), where all dependencies are already bundled in, use
api 'net.fabricmc:fabric-semver:<VERSION>:fat'
instead.