{"record":{"id":"a43178a2425c750e","repo":"apache/maven","slug":"cannot-change-the-groupid-for-an-attached-artifact","errorCode":null,"errorMessage":"Cannot change the groupId for an attached artifact. It is derived from the main artifact.","messagePattern":"Cannot change the groupId for an attached artifact\\. It is derived from the main artifact\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java","lineNumber":114,"sourceCode":"    public void setBaseVersion(String baseVersion) {\n        throw new UnsupportedOperationException(\"Cannot change the version information for an attached artifact.\"\n                + \" It is derived from the main artifact.\");\n    }\n\n    @Override\n    public String getDownloadUrl() {\n        return parent.getDownloadUrl();\n    }\n\n    @Override\n    public void setDownloadUrl(String downloadUrl) {\n        throw new UnsupportedOperationException(\"Cannot change the download information for an attached artifact.\"\n                + \" It is derived from the main artifact.\");\n    }\n\n    @Override\n    public void setGroupId(String groupId) {\n        throw new UnsupportedOperationException(\n                \"Cannot change the groupId for an attached artifact.\" + \" It is derived from the main artifact.\");\n    }\n\n    @Override\n    public ArtifactRepository getRepository() {\n        return parent.getRepository();\n    }\n\n    @Override\n    public void setRepository(ArtifactRepository repository) {\n        throw new UnsupportedOperationException(\"Cannot change the repository information for an attached artifact.\"\n                + \" It is derived from the main artifact.\");\n    }\n\n    @Override\n    public String getScope() {\n        return parent.getScope();\n    }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java#L96-L132","documentation":"groupId is part of the identity an attached artifact inherits from its main artifact, so setGroupId always throws UnsupportedOperationException.","triggerScenarios":"Calling setGroupId(...) on an AttachedArtifact, typically relocation or coordinates-rewrite tooling processing every artifact in a project.","commonSituations":"Group-rename or relocation tooling that rewrites coordinates on all artifacts; generic artifact transformation pipelines unaware of the attached/main distinction.","solutions":["Change the groupId on the project/main artifact before attachments are created","Create a standalone DefaultArtifact with the new groupId if independence is required","Skip attached artifacts during coordinate rewrites"],"exampleFix":"// before\nattached.setGroupId(\"org.example.new\");\n\n// after\nproject.getArtifact().setGroupId(\"org.example.new\");","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isAttachedArtifact(Artifact a) {\n    return a instanceof org.apache.maven.project.artifact.AttachedArtifact;\n}","tryCatchPattern":"if (isAttachedArtifact(artifact)) {\n    project.getArtifact().setGroupId(groupId);\n} else {\n    artifact.setGroupId(groupId);\n}","preventionTips":["Rewrite coordinates at the project level before attachments exist","Test coordinate-rewrite tooling against projects with attached artifacts"],"tags":["maven","artifact","attached-artifact","immutable","coordinates"],"backgroundTag":"immutable-object-mutation","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}