Lab 02 — Semantic Versioning Engine
Implement a SemVer 2.0.0-compliant parser and comparator — the tool every release manager uses to decide whether a dependency upgrade is safe to ship.
What you build
| Class | Responsibility |
|---|---|
SemanticVersion | Parses and compares SemVer strings; implements Comparable |
CompatibilityLevel | Enum: MAJOR / MINOR / PATCH / PRE_RELEASE / EQUAL |
VersionComparator | Classifies the impact of a version bump |
Run the tests
mvn clean test
Expected: 20 tests, 0 failures.
Key concepts
Precedence rules (SemVer 2.0.0 §11)
- Compare MAJOR, then MINOR, then PATCH numerically.
- Release (
1.2.3) > same version with pre-release (1.2.3-rc.1). - Pre-release identifiers, dot-separated, left-to-right:
- Both numeric → integer comparison (
beta.9 < beta.10) - Numeric vs alphanumeric → numeric is lower (
1 < alpha) - Both alphanumeric → ASCII order
- Both numeric → integer comparison (
- Shorter tuple is lower when shared identifiers are equal.
- Build metadata (
+build.1) is ignored for comparison.
Canonical ordering (from the spec)
1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta
< 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11
< 1.0.0-rc.1 < 1.0.0
Interview talking points
- "Bumping MAJOR means callers must update their code; that requires a deprecation cycle in Apache projects."
- "Two versions with different build metadata are equal — build metadata is for CI traceability, not release identity."
- "Numeric pre-release IDs are compared as integers, not strings —
beta.9 < beta.10, not the other way around."