https://semver.org/lang/zh-CN/
jsemver - 一个进行语义化版本号处理的库
maven依赖:
<dependency> <groupId>com.github.zafarkhaja</groupId> <artifactId>java-semver</artifactId> <version>0.9.0</version> </dependency>
示例代码1:
import com.github.zafarkhaja.semver.Version; Version v = Version.valueOf("1.0.0-rc.1+build.1"); int major = v.getMajorVersion(); // 1 int minor = v.getMinorVersion(); // 0 int patch = v.getPatchVersion(); // 0 String normal = v.getNormalVersion(); // "1.0.0" String preRelease = v.getPreReleaseVersion(); // "rc.1" String build = v.getBuildMetadata(); // "build.1" String str = v.toString(); // "1.0.0-rc.1+build.1"
示例代码2:
import com.github.zafarkhaja.semver.Version; Version v1 = Version.valueOf("1.0.0-rc.1+build.1"); Version v2 = Version.valueOf("1.3.7+build.2.b8f12d7"); int result = v1.compareTo(v2); // < 0 boolean result = v1.equals(v2); // false boolean result = v1.greaterThan(v2); // false boolean result = v1.greaterThanOrEqualTo(v2); // false boolean result = v1.lessThan(v2); // true boolean result = v1.lessThanOrEqualTo(v2); // true
示例代码3
import com.github.zafarkhaja.semver.Version; import static com.github.zafarkhaja.semver.expr.CompositeExpression.Helper.*; Version v = Version.valueOf("1.0.0-beta"); boolean result = v.satisfies(gte("1.0.0").and(lt("2.0.0"))); // false
https://keepachangelog.com/zh-CN/1.0.0/