apache/maven · error · UnsupportedOperationException

Cannot change the groupId for an attached artifact. It is de

Error message

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

What it means

groupId is part of the identity an attached artifact inherits from its main artifact, so setGroupId always throws UnsupportedOperationException.

Source

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

    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.");
    }

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

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Change the groupId on the project/main artifact before attachments are created
  2. Create a standalone DefaultArtifact with the new groupId if independence is required
  3. Skip attached artifacts during coordinate rewrites

Example fix

// before
attached.setGroupId("org.example.new");

// after
project.getArtifact().setGroupId("org.example.new");
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().setGroupId(groupId);
} else {
    artifact.setGroupId(groupId);
}

Prevention

When it happens

Trigger: Calling setGroupId(...) on an AttachedArtifact, typically relocation or coordinates-rewrite tooling processing every artifact in a project.

Common situations: Group-rename or relocation tooling that rewrites coordinates on all artifacts; generic artifact transformation pipelines unaware of the attached/main distinction.

Related errors


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