Skip to content

AFS-Agentics/semverj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cover

SemVerJ

Semantic Versioning 2.0.0 library for Java 21+ — parse, compare, and manipulate semver strings with a clean, fluent API.

Java License Maven SemVer

Features

  • Parse — Parse any valid SemVer 2.0.0 string (including pre-release and build metadata)
  • Compare — Compare versions using proper SemVer precedence rules
  • Increment — Generate next major/minor/patch versions
  • Range matching — Support for ^, ~, >=, <=, >, <, wildcard (x/*), and hyphen ranges
  • Builder API — Fluent builder for constructing versions programmatically
  • Immutable & thread-safe — All instances are immutable and safe for concurrent use
  • Zero dependencies — Pure Java, no external runtime dependencies

Installation

Maven

Add the following to your pom.xml:

<dependency>
    <groupId>com.afsagentics</groupId>
    <artifactId>semverj</artifactId>
    <version>0.1.0</version>
</dependency>

Manual

Download the JAR from the releases page and add it to your classpath.

Usage

Parsing

SemVer v1 = SemVer.parse("1.2.3");
SemVer v2 = SemVer.parse("2.0.0-rc.1+build.42");

System.out.println(v1.major());    // 1
System.out.println(v1.minor());    // 2
System.out.println(v1.patch());    // 3
System.out.println(v1.isStable()); // true
System.out.println(v2.isPreRelease()); // true

Building

SemVer v = SemVer.builder()
    .major(1)
    .minor(0)
    .patch(0)
    .preRelease("alpha")
    .build();
// → "1.0.0-alpha"

SemVer v2 = SemVer.of(2, 1, 3);
SemVer v3 = SemVer.of(3, 0, 0, "rc.2", "build.2024");

Comparison

SemVer a = SemVer.parse("1.0.0");
SemVer b = SemVer.parse("2.0.0");

a.isGreaterThan(b); // false
a.isLessThan(b);    // true
a.isEqualTo(b);     // false

// Pre-release precedence
SemVer.parse("1.0.0-alpha").compareTo(SemVer.parse("1.0.0"));
// → -1  (pre-release sorts before release)

Incrementing

SemVer v = SemVer.parse("1.2.3");
v.nextMajor();  // 2.0.0
v.nextMinor();  // 1.3.0
v.nextPatch();  // 1.2.4

v.withPreRelease("beta");         // 1.2.3-beta
v.clearPreRelease();              // 1.2.3

Range Matching

VersionRange range = VersionRange.parse("^1.2.3");
range.satisfies("1.2.3");   // true
range.satisfies("1.9.9");   // true
range.satisfies("2.0.0");   // false

// Tilde range
VersionRange.parse("~1.2.0").satisfies("1.2.5");  // true

// Comparison operators
VersionRange.parse(">=1.0.0 <2.0.0").satisfies("1.5.0");  // true

// Wildcard
VersionRange.parse("1.2.x").satisfies("1.2.99");  // true

// Hyphen range
VersionRange.parse("1.0.0 - 2.0.0").satisfies("1.5.0");  // true

Building from Source

git clone https://github.com/AFS-Agentics/semverj.git
cd semverj
mvn clean package

Running Tests

mvn test

API Documentation

Javadoc is included in the source and can be generated with:

mvn javadoc:javadoc

License

MIT License — see LICENSE for details.

About

Semantic Versioning 2.0.0 library for Java 21+ — parse, compare, manipulate semver strings with a fluent API

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages