{"record":{"id":"bd01feac8c655d6c","repo":"apache/maven","slug":"cannot-change-the-scoping-information-for-an-attac","errorCode":null,"errorMessage":"Cannot change the scoping information for an attached artifact. It is derived from the main artifact.","messagePattern":"Cannot change the scoping 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":136,"sourceCode":"    @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    }\n\n    @Override\n    public void setVersion(String version) {\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 VersionRange getVersionRange() {\n        return parent.getVersionRange();\n    }","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java#L118-L154","documentation":"Scope is a dependency attribute inherited from the main artifact: getScope() delegates to the parent, and setScope throws UnsupportedOperationException. Attached artifacts are not dependency declarations, so their scope cannot be edited.","triggerScenarios":"Calling setScope(...) on an AttachedArtifact, e.g. classpath-composition code trying to widen or narrow scopes on every artifact of a project.","commonSituations":"Scope-manipulation logic that treats project.getAttachedArtifacts() like dependency artifacts; plugins reused from DefaultArtifact code paths.","solutions":["Adjust scope on the Dependency declaration or the main artifact instead: attached artifacts have no independent scope","Configure scope changes via dependency declarations or plugin configuration","Skip attached artifacts in scope processing"],"exampleFix":"// before\nattached.setScope(Artifact.SCOPE_RUNTIME);\n\n// after\n// scope belongs to dependencies, not attached artifacts\ndependency.setScope(Artifact.SCOPE_RUNTIME);","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    throw new IllegalStateException(\"scope is a dependency attribute; set it on the Dependency\");\n}","preventionTips":["Never treat attached artifacts as dependency declarations","Configure scope changes on dependencies or plugin configuration"],"tags":["maven","artifact","attached-artifact","immutable","scope"],"backgroundTag":"immutable-object-mutation","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}