Fix comparison cycles in version qualifiers
Removed comparison cycles from the Maven 4 `compat/maven-artifact` implementation of `ComparableVersion` while preserving release aliases, numeric precedence, artifact equality, and ordering hashes.
apache/maven · #13102
Build correctness fix
Maven 4's compatibility-layer version ordering now satisfies the `Comparable` contract for numeric-prefixed and unknown qualifiers, keeping sorted collections and version-range selection deterministic.
Problem
Mixed qualifier layouts could produce an illegal ordering cycle such as `0-alpha > x > 0 > 0-alpha`. That violates transitivity and can make `TreeSet`, collection sorting, and `VersionRange.matchVersion()` fail or behave inconsistently.
Approach
Compares qualifier lists with scalar qualifiers by content instead of fixed item-type rank, normalizes zero-prefixed nesting, keeps release-zero aliases equivalent, and aligns ordering hashes with the corrected comparison semantics.
Impact and scope
- Restores antisymmetric and transitive ordering for version values used by Maven compatibility APIs.
- Prevents cyclic comparator results from destabilizing sorted collections and dependency version-range selection.
- Preserves established Maven qualifier behavior rather than replacing it with SemVer or changing the independent Resolver version scheme.
Validation
- Regression coverage includes the reported cycle, mixed qualifier layouts, release aliases, numeric boundaries, artifact equality and hashing, and version-range selection.
- An exhaustive property test checks antisymmetry, transitivity, and substitution across more than 219 version strings; Maven verification and Core IT also passed.
- Two Maven reviewers approved the final compat-only scope, and all listed build and integration-test jobs passed across macOS, Ubuntu, Windows, and JDK 17, 21, and 25. The GitHub-verified merge commit credits Goutam Adwant and closed MNG-6568.