apache/maven · error · OverConstrainedVersionException

No versions are present in the repository for the artifact w

Error message

No versions are present in the repository for the artifact with a range " + versionRange

What it means

In DefaultLegacyArtifactCollector's ranged-version handling, the list of available versions retrieved from repository metadata came back empty (after sorting), so versionRange.matchVersion(versions) returned null and versions.isEmpty() is true. OverConstrainedVersionException is thrown with 'No versions are present in the repository for the artifact with a range <range>', carrying the artifact and the child remote repositories that were searched.

Source

Thrown at compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java:473

                                    // TODO maybe its better to just pass the range through to retrieval and use a
                                    // transformation?
                                    ArtifactVersion version;
                                    if (!artifact.isSelectedVersionKnown()) {
                                        List<ArtifactVersion> versions = artifact.getAvailableVersions();
                                        if (versions == null) {
                                            versions = source.retrieveAvailableVersions(metadataRequest);
                                            artifact.setAvailableVersions(versions);
                                        }

                                        Collections.sort(versions);

                                        VersionRange versionRange = artifact.getVersionRange();

                                        version = versionRange.matchVersion(versions);

                                        if (version == null) {
                                            if (versions.isEmpty()) {
                                                throw new OverConstrainedVersionException(
                                                        "No versions are present in the repository for the artifact"
                                                                + " with a range " + versionRange,
                                                        artifact,
                                                        childRemoteRepositories);
                                            }

                                            throw new OverConstrainedVersionException(
                                                    "Couldn't find a version in " + versions + " to match range "
                                                            + versionRange,
                                                    artifact,
                                                    childRemoteRepositories);
                                        }
                                    } else {
                                        version = artifact.getSelectedVersion();
                                    }

                                    artifact.selectVersion(version.toString());
                                    fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child);

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Verify groupId/artifactId of the ranged dependency against the search page of your repository manager
  2. Confirm the repository hosting the artifact is actually declared and reachable in the current build (mvn help:effective-pom, and check mirror rules in settings.xml)
  3. Refresh with mvn -U in case cached empty metadata is stale
  4. If this is a first-release situation, publish at least one version of the artifact before depending on it via a range

Example fix

# before: artifact not in any declared repo
mvn verify   # -> No versions are present in the repository ...

# after: add the repository that actually hosts it
<repositories>
  <repository>
    <id>example-releases</id>
    <url>https://repo.example.com/releases</url>
  </repository>
</repositories>
mvn -U verify
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: confirm at least one version is available for the ranged dependency
List<ArtifactVersion> versions = metadataSource.retrieveAvailableVersions(request);
if (versions == null || versions.isEmpty()) {
    throw new IllegalStateException(
            "No versions found for " + artifact + " — verify groupId/artifactId and repositories");
}

Try / catch

catch (OverConstrainedVersionException e) {
    if (e.getMessage().contains("No versions are present")) {
        // artifact metadata absent entirely: check coordinates and repo access
        guideUserToCheckCoordinates(artifact, childRemoteRepositories);
    } else {
        // versions exist but none match: adjust the range
        guideUserToAdjustRange(artifact);
    }
}

Prevention

When it happens

Trigger: A dependency declared with a version range where retrieveAvailableVersions returns an empty list: the artifact's maven-metadata.xml lists no versions, or the artifact does not exist at all in the searched repositories (wrong groupId/artifactId, repo not reachable, or artifact never deployed).

Common situations: Typo in groupId/artifactId so no metadata is ever found; relying on an internal repository that does not mirror the needed repo; the artifact was renamed or never released; offline/local-only resolution where the metadata was never cached; snapshot-only artifacts where release metadata is absent.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/38e6a1a968a55c57. Report an issue: GitHub.