apache/maven · error · VersionParserException
Unable to parse version:
Error message
Unable to parse version:
What it means
DefaultModelVersionParser's DefaultVersion wraps the resolver VersionScheme; parsing a version string that the scheme rejects throws VersionParserException('Unable to parse version: <input>'). The generic parse is used when a raw string (e.g. from a POM property or plugin parameter) must become a Version object, and the underlying scheme (typically GenericVersionScheme) rejects malformed input such as empty strings.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelVersionParser.java:90
requireNonNull(constraint, "constraint");
return new DefaultVersionConstraint(versionScheme, constraint);
}
static class DefaultVersion implements Version {
private final VersionScheme versionScheme;
private final org.eclipse.aether.version.Version delegate;
DefaultVersion(VersionScheme versionScheme, org.eclipse.aether.version.Version delegate) {
this.versionScheme = versionScheme;
this.delegate = delegate;
}
DefaultVersion(VersionScheme versionScheme, String delegateValue) {
this.versionScheme = versionScheme;
try {
this.delegate = versionScheme.parseVersion(delegateValue);
} catch (InvalidVersionSpecificationException e) {
throw new VersionParserException("Unable to parse version: " + delegateValue, e);
}
}
@Override
public int compareTo(Version o) {
if (o instanceof DefaultVersion defaultVersion) {
return delegate.compareTo(defaultVersion.delegate);
} else {
return compareTo(new DefaultVersion(versionScheme, o.toString()));
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {View on GitHub (pinned to e4093d4e12)
Solutions
- Trim and reject empty/uninterpolated ('${...}') strings before parsing
- Catch VersionParserException and report which string failed with the POM/location context
- Where possible use versionScheme.parseVersion indirectly through Model API which surfaces better diagnostics
Example fix
// before
Version v = session.getService(VersionParser.class).parseVersion(props.getProperty('project.version'));
// after
String raw = props.getProperty('project.version');
if (raw == null || raw.isBlank() || raw.contains('${')) {
throw new IllegalArgumentException('project.version not interpolated: ' + raw);
}
Version v = session.getService(VersionParser.class).parseVersion(raw.trim()); Defensive patterns
Strategy: try-catch
Validate before calling
if (version == null || version.isBlank() || version.contains('${')) {
throw new IllegalArgumentException('Version string is blank or uninterpolated: ' + version);
} Try / catch
try {
Version v = parser.parseVersion(raw);
} catch (VersionParserException e) {
throw new IllegalArgumentException('Bad version "' + raw + '" in ' + source, e);
} Prevention
- Trim version strings and reject blanks/uninterpolated properties
- Carry the POM location/context in wrapped errors for diagnosability
- Prefer comparing already-parsed Version objects over re-parsing strings
When it happens
Trigger: session.getService(VersionParser.class).parseVersion(''), parseVersion('${some.unset.property}'), or a version string with characters the version scheme cannot tokenize; also compareTo on a foreign Version implementation that re-parses its toString().
Common situations: POM properties for versions left uninterpolated; user input or CLI args (-Dversion=...) passed to version comparisons; empty default version strings in code; version strings with stray whitespace.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Repository identifier missing
- URL missing for repository " + id
- Repository identifier missing
- URL missing for repository {}
- Cannot find ArtifactRepositoryLayout instance for: %s %s
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/4226f54b2e63203c.
Report an issue: GitHub.