apache/maven · error · IllegalArgumentException

The given artifact is not resolved

Error message

The given artifact is not resolved

What it means

Thrown by AbstractSession.getArtifact(DownloadedArtifact.class, artifact) when the underlying Eclipse Resolver artifact has a null path, meaning it has never been resolved to a file in the local repository. The Maven API distinguishes plain Artifact (metadata only) from DownloadedArtifact (backed by a resolved file), and only the latter can be created from a resolved artifact. Requesting a DownloadedArtifact from an unresolved artifact is a programming error, not a resolution failure.

Source

Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/AbstractSession.java:263

        return allNodes.computeIfAbsent(node, n -> new DefaultNode(this, n, verbose));
    }

    @Nonnull
    @Override
    public Artifact getArtifact(@Nonnull org.eclipse.aether.artifact.Artifact artifact) {
        return getArtifact(Artifact.class, artifact);
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T extends Artifact> T getArtifact(Class<T> clazz, org.eclipse.aether.artifact.Artifact artifact) {
        Cache<org.eclipse.aether.artifact.Artifact, Artifact> map = allArtifacts.computeIfAbsent(
                clazz, c -> Cache.newCache(Cache.ReferenceType.WEAK, "AbstractSession-Artifacts-" + c.getSimpleName()));
        if (clazz == Artifact.class) {
            return (T) map.computeIfAbsent(artifact, a -> new DefaultArtifact(this, a));
        } else if (clazz == DownloadedArtifact.class) {
            if (artifact.getPath() == null) {
                throw new IllegalArgumentException("The given artifact is not resolved");
            } else {
                return (T) map.computeIfAbsent(artifact, a -> new DefaultDownloadedArtifact(this, a));
            }
        } else if (clazz == ProducedArtifact.class) {
            return (T) map.computeIfAbsent(artifact, a -> new DefaultProducedArtifact(this, a));
        } else {
            throw new IllegalArgumentException("Unsupported Artifact class: " + clazz);
        }
    }

    @Nonnull
    @Override
    public Dependency getDependency(@Nonnull org.eclipse.aether.graph.Dependency dependency) {
        return allDependencies.computeIfAbsent(dependency, d -> new DefaultDependency(this, d));
    }

    @Override
    public List<org.eclipse.aether.repository.RemoteRepository> toRepositories(List<RemoteRepository> repositories) {

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Resolve the artifact first with session.getService(ArtifactResolver.class).resolve(request) so the resolver sets a path, then call getArtifact(DownloadedArtifact.class, ...)
  2. If you only need coordinates/properties and not the file, request Artifact.class instead of DownloadedArtifact.class
  3. Check aetherArtifact.getPath() != null before asking for a DownloadedArtifact and fail with a clearer message

Example fix

// before
DownloadedArtifact da = session.getArtifact(DownloadedArtifact.class, aetherArtifact);

// after
if (aetherArtifact.getPath() == null) {
    throw new IllegalStateException('artifact not resolved: ' + aetherArtifact);
}
DownloadedArtifact da = session.getArtifact(DownloadedArtifact.class, aetherArtifact);
Defensive patterns

Strategy: validation

Validate before calling

if (aetherArtifact.getPath() == null) {
    throw new IllegalStateException(
            'Artifact ' + aetherArtifact + ' has no path; resolve it before requesting a DownloadedArtifact');
}

Prevention

When it happens

Trigger: Calling session.getArtifact(DownloadedArtifact.class, aetherArtifact) (directly or via a helper) where the org.eclipse.aether.artifact.Artifact was built from coordinates only (e.g. new DefaultArtifact('g:a:v:jar')) and never passed through ArtifactResolver / RepositorySystem.resolveArtifacts, so artifact.getPath() returns null.

Common situations: Maven 4 plugin or extension code that mixes the new org.apache.maven.api Session with raw resolver artifacts; resolving an artifact, then re-creating coordinates objects and losing the path; unit tests that construct artifacts by hand instead of resolving them; code that assumes getArtifact always returns a file-backed instance.

Related errors


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