{"record":{"id":"00b04ae8e2c895e6","repo":"apache/maven","slug":"cannot-change-the-repository-information-for-an-at","errorCode":null,"errorMessage":"Cannot change the repository information for an attached artifact. It is derived from the main artifact.","messagePattern":"Cannot change the repository information 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":125,"sourceCode":"    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    }\n\n    @Override\n    public void setScope(String scope) {\n        throw new UnsupportedOperationException(\"Cannot change the scoping information for an attached artifact.\"\n                + \" It is derived from the main artifact.\");\n    }\n\n    @Override\n    public String getVersion() {\n        return parent.getVersion();\n    }","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java#L107-L143","documentation":"The repository an artifact was resolved from is delegated to the main artifact: getRepository() returns the parent's repository, and setRepository throws UnsupportedOperationException on attached artifacts.","triggerScenarios":"Calling setRepository(...) on an AttachedArtifact, usually resolver or caching code recording where each artifact came from.","commonSituations":"Resolver bridges or artifact caches stamping origin repositories onto all artifacts of a project; metadata collectors iterating getAttachedArtifacts().","solutions":["Stamp the repository on the main artifact before attaching","Track origin metadata in your own map keyed by artifact id instead of on the artifact","Skip attached artifacts when stamping repositories"],"exampleFix":"// before\nattached.setRepository(localRepo);\n\n// after\nproject.getArtifact().setRepository(localRepo);","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().setRepository(repo);\n} else {\n    artifact.setRepository(repo);\n}","preventionTips":["Track artifact origin in your own metadata keyed by artifact id","Stamp repositories on the main artifact only"],"tags":["maven","artifact","attached-artifact","immutable","repository"],"backgroundTag":"immutable-object-mutation","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}