apache/maven · error · UnsupportedOperationException

Cannot change the download information for an attached artif

Error message

Cannot change the download information for an attached artifact. It is derived from the main artifact.

What it means

Download-location metadata is inherited from the main artifact: getDownloadUrl() delegates to the parent and setDownloadUrl throws UnsupportedOperationException on attached artifacts.

Source

Thrown at impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java:108

    @Override
    public String getBaseVersion() {
        return parent.getBaseVersion();
    }

    @Override
    public void setBaseVersion(String baseVersion) {
        throw new UnsupportedOperationException("Cannot change the version information for an attached artifact."
                + " It is derived from the main artifact.");
    }

    @Override
    public String getDownloadUrl() {
        return parent.getDownloadUrl();
    }

    @Override
    public void setDownloadUrl(String downloadUrl) {
        throw new UnsupportedOperationException("Cannot change the download information for an attached artifact."
                + " It is derived from the main artifact.");
    }

    @Override
    public void setGroupId(String groupId) {
        throw new UnsupportedOperationException(
                "Cannot change the groupId for an attached artifact." + " It is derived from the main artifact.");
    }

    @Override
    public ArtifactRepository getRepository() {
        return parent.getRepository();
    }

    @Override
    public void setRepository(ArtifactRepository repository) {
        throw new UnsupportedOperationException("Cannot change the repository information for an attached artifact."
                + " It is derived from the main artifact.");

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Set the download URL on the main artifact instead
  2. Prefer project-level distributionManagement/relocation configuration over per-artifact mutation
  3. Skip attached artifacts when stamping URLs

Example fix

// before
attached.setDownloadUrl(url);

// after
project.getArtifact().setDownloadUrl(url);
Defensive patterns

Strategy: type-guard

Type guard

static boolean isAttachedArtifact(Artifact a) {
    return a instanceof org.apache.maven.project.artifact.AttachedArtifact;
}

Try / catch

if (isAttachedArtifact(artifact)) {
    project.getArtifact().setDownloadUrl(url);
} else {
    artifact.setDownloadUrl(url);
}

Prevention

When it happens

Trigger: Calling setDownloadUrl(...) on an AttachedArtifact, e.g. relocation or deployment code that stamps a download URL on every produced artifact.

Common situations: Deploy/relocation tooling iterating over project artifacts including attached ones; code moved from DefaultArtifact where the setter was permitted.

Related errors


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