apache/maven · error · ArtifactMetadataRetrievalException
Invalid version for dependency " + dependency.getManagementK
Error message
Invalid version for dependency " + dependency.getManagementKey() + ": " + e.getMessage()
What it means
Thrown by MavenMetadataSource while creating an Artifact for a transitive dependency during metadata retrieval (the legacy resolution path used to discover a dependency's dependencies). createDependencyArtifact catches InvalidVersionSpecificationException from the artifact factory and rethrows it as ArtifactMetadataRetrievalException, naming the dependency's management key (groupId:artifactId:type) and the invalid spec. This means the <version> of some dependency in the resolved graph is not a parseable version or range.
Source
Thrown at compat/maven-compat/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java:343
}
}
repositories = new ArrayList<>(repos.values());
}
return repositories;
}
private Artifact createDependencyArtifact(Dependency dependency, Artifact owner, Artifact pom)
throws ArtifactMetadataRetrievalException {
try {
String inheritedScope = (owner != null) ? owner.getScope() : null;
ArtifactFilter inheritedFilter = (owner != null) ? owner.getDependencyFilter() : null;
return createDependencyArtifact(artifactFactory, dependency, inheritedScope, inheritedFilter);
} catch (InvalidVersionSpecificationException e) {
throw new ArtifactMetadataRetrievalException(
"Invalid version for dependency " + dependency.getManagementKey() + ": " + e.getMessage(), e, pom);
}
}
private static Artifact createDependencyArtifact(
ArtifactFactory factory, Dependency dependency, String inheritedScope, ArtifactFilter inheritedFilter)
throws InvalidVersionSpecificationException {
String effectiveScope = getEffectiveScope(dependency.getScope(), inheritedScope);
if (effectiveScope == null) {
return null;
}
VersionRange versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
Artifact dependencyArtifact = factory.createDependencyArtifact(
dependency.getGroupId(),
dependency.getArtifactId(),View on GitHub (pinned to e4093d4e12)
Solutions
- Run with -X to see the full graph and identify which artifact's POM carries the bad version (the management key in the message names it)
- Delete the offending artifact's directory under ~/.m2/repository and re-resolve in case the cached POM is corrupt
- If the bad version comes from a dependencyManagement section you control, correct the version/range there
- Exclude the offending dependency (<exclusions>) or pin a good version via dependencyManagement until upstream fixes their POM
- Report/fix the broken POM in the project that publishes it
Example fix
<!-- before: broken range pulled in transitively -->
<dependency>
<groupId>bad.libs</groupId><artifactId>bad-lib</artifactId><version>[1.0,2.0</version>
</dependency>
<!-- after: pin a fixed version or exclude -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>bad.libs</groupId><artifactId>bad-lib</artifactId><version>1.5</version>
</dependency>
</dependencies>
</dependencyManagement> Defensive patterns
Strategy: validation
Validate before calling
// Pre-parse every dependency version you control before the build
try {
org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec(dep.getVersion());
} catch (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException e) {
fail("dependency " + dep.getManagementKey() + " has invalid version: " + dep.getVersion());
} Prevention
- Pin exact versions in dependencyManagement to shield against broken transitive ranges
- Lint your own POM versions in CI (enforcer requireUpperBoundDeps or a custom rule)
- Purge suspect artifacts from the local repo when messages look like corruption
When it happens
Trigger: A dependency (usually a transitive one, in a POM Maven just fetched) has a malformed version string: unbalanced range like '[1.0,2.0', empty bounds, or a non-parseable literal such that VersionRange/DefaultArtifactVersion parsing throws InvalidVersionSpecificationException.
Common situations: A third-party POM published with a broken version range; a property left unresolved in a consumed POM (version literally '${foo.version}'); mixed old Maven 2-era metadata; LATEST/RELEASE markers in odd positions; corrupt downloaded POM in the local repo.
Related errors
- A dependency has introduced a cycle
- Unable to get a selected Version for {}
- Failed to process POM for " + artifact.getId() + ": " + miss
- Unable to download the artifact from any repository
- No versions matched the requested parent version range '%s'
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/419cb16677dfe142.
Report an issue: GitHub.