apache/maven · error · UnsupportedOperationException
Cannot change the repository information for an attached art
Error message
Cannot change the repository information for an attached artifact. It is derived from the main artifact.
What it means
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.
Source
Thrown at impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java:125
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();
}
@Override
public void setScope(String scope) {
throw new UnsupportedOperationException("Cannot change the scoping information for an attached artifact."
+ " It is derived from the main artifact.");
}
@Override
public String getVersion() {
return parent.getVersion();
}View on GitHub (pinned to e4093d4e12)
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
Example fix
// before attached.setRepository(localRepo); // after project.getArtifact().setRepository(localRepo);
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().setRepository(repo);
} else {
artifact.setRepository(repo);
} Prevention
- Track artifact origin in your own metadata keyed by artifact id
- Stamp repositories on the main artifact only
When it happens
Trigger: Calling setRepository(...) on an AttachedArtifact, usually resolver or caching code recording where each artifact came from.
Common situations: Resolver bridges or artifact caches stamping origin repositories onto all artifacts of a project; metadata collectors iterating getAttachedArtifacts().
Related errors
- Cannot change the artifactId for an attached artifact. It is
- Cannot change the version information for an attached artifa
- Cannot change the download information for an attached artif
- Cannot change the groupId for an attached artifact. It is de
- Cannot change the scoping information for an attached artifa
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/00b04ae8e2c895e6.
Report an issue: GitHub.