apache/maven · error · UnsupportedOperationException
Cannot change the version information for an attached artifa
Error message
Cannot change the version information for an attached artifact. It is derived from the main artifact.
What it means
AttachedArtifact delegates available-version metadata to its parent: getAvailableVersions() returns the main artifact's list, while setAvailableVersions throws UnsupportedOperationException because that metadata is owned by the main artifact.
Source
Thrown at impl/maven-core/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java:86
public AttachedArtifact(Artifact parent, String type, ArtifactHandler artifactHandler) {
this(parent, type, null, artifactHandler);
}
@Override
public void setArtifactId(String artifactId) {
throw new UnsupportedOperationException(
"Cannot change the artifactId for an attached artifact." + " It is derived from the main artifact.");
}
@Override
public List<ArtifactVersion> getAvailableVersions() {
return parent.getAvailableVersions();
}
@Override
public void setAvailableVersions(List<ArtifactVersion> availableVersions) {
throw new UnsupportedOperationException("Cannot change the version information for an attached artifact."
+ " It is derived from the main artifact.");
}
@Override
public String getBaseVersion() {
return parent.getBaseVersion();
}
@Override
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();
}View on GitHub (pinned to e4093d4e12)
Solutions
- Set available versions on the main artifact (project.getArtifact().setAvailableVersions(...)) and let attachments inherit it
- Use a standalone DefaultArtifact for artifacts that need independent metadata
- Skip attached artifacts when stamping metadata
Example fix
// before
for (Artifact a : project.getAttachedArtifacts()) {
a.setAvailableVersions(versions);
}
// after
project.getArtifact().setAvailableVersions(versions); 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().setAvailableVersions(versions); // metadata is owned by the main artifact
} else {
artifact.setAvailableVersions(versions);
} Prevention
- Apply version-metadata updates to the main artifact once, not per attached artifact
- Skip attached artifacts in generic normalization passes
When it happens
Trigger: Calling setAvailableVersions(list) on an AttachedArtifact, e.g. resolution or version-metadata code that stamps available versions onto every artifact of a project.
Common situations: Version-range tooling or resolvers iterating project.getAttachedArtifacts() and normalizing metadata on each entry; code ported from DefaultArtifact-based flows where the setter worked.
Related errors
- Cannot change the artifactId for an attached artifact. It is
- Cannot change the download information for an attached artif
- Cannot change the groupId for an attached artifact. It is de
- Cannot change the repository information for an attached art
- Cannot change the scoping information for an attached artifa
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/16f0ae410097590e.
Report an issue: GitHub.