gradle/gradle · error · IllegalArgumentException
Cannot resolve the artifacts for component %s with unsupport
Error message
Cannot resolve the artifacts for component %s with unsupported type %s.
What it means
Besides rejecting ProjectComponentIdentifier, validateComponentIdentifier() accepts only ModuleComponentIdentifier. Any other ComponentIdentifier implementation — OSGi identifiers, custom identifiers created by plugins, or ids from unrelated APIs — falls through to this generic IllegalArgumentException naming the component and the actual class of the unsupported identifier.
Source
Thrown at platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/query/DefaultArtifactResolutionQuery.java:196
ComponentIdentifier validId = validateComponentIdentifier(componentId);
componentResults.add(buildComponentResult(validId, componentMetaDataResolver, artifactResolver));
} catch (Exception t) {
componentResults.add(new DefaultUnresolvedComponentResult(componentId, t));
}
}
return new DefaultArtifactResolutionResult(componentResults);
}
private ComponentIdentifier validateComponentIdentifier(ComponentIdentifier componentId) {
if (componentId instanceof ModuleComponentIdentifier) {
return componentId;
}
if (componentId instanceof ProjectComponentIdentifier) {
throw new IllegalArgumentException(String.format("Cannot query artifacts for a project component (%s).", componentId.getDisplayName()));
}
throw new IllegalArgumentException(String.format("Cannot resolve the artifacts for component %s with unsupported type %s.", componentId.getDisplayName(), componentId.getClass().getName()));
}
private ComponentArtifactsResult buildComponentResult(ComponentIdentifier componentId, ComponentMetaDataResolver componentMetaDataResolver, ArtifactResolver artifactResolver) {
BuildableComponentResolveResult moduleResolveResult = new DefaultBuildableComponentResolveResult();
componentMetaDataResolver.resolve(componentId, DefaultComponentOverrideMetadata.EMPTY, moduleResolveResult);
ComponentArtifactResolveMetadata component = moduleResolveResult.getState().prepareForArtifactResolution().getArtifactMetadata();
DefaultComponentArtifactsResult componentResult = new DefaultComponentArtifactsResult(component.getId());
for (Class<? extends Artifact> artifactType : artifactTypes) {
addArtifacts(componentResult, artifactType, component, artifactResolver);
}
return componentResult;
}
private <T extends Artifact> void addArtifacts(
DefaultComponentArtifactsResult artifacts,
Class<T> type,
ComponentArtifactResolveMetadata component,
ArtifactResolver artifactResolverView on GitHub (pinned to 534f27719b)
Solutions
- Pass only real ModuleComponentIdentifier instances into forComponents(...) — best obtained from a ResolutionResult.
- Filter unknown ids out: keep only ids where id instanceof ModuleComponentIdentifier.
- If the component is local to the build (project or file-based), use configuration artifact views or file collections instead of ArtifactResolutionQuery.
Example fix
// before
query.forComponents(Arrays.asList(osgiId, customId)) // neither is a ModuleComponentIdentifier
.withArtifacts(ComponentWithModule.class, MavenModuleArtifact.class).execute()
// after
query.forComponents(allIds.findAll { it instanceof ModuleComponentIdentifier })
.withArtifacts(ComponentWithModule.class, MavenModuleArtifact.class).execute() Defensive patterns
Strategy: type-guard
Validate before calling
def moduleIds = allIds.findAll { isQueryableComponent(it) }
def result = dependencies.createArtifactResolutionQuery()
.forComponents(moduleIds)
.withArtifacts(ComponentWithModule.class, MavenModuleArtifact.class).execute() Type guard
static boolean isQueryableComponent(ComponentIdentifier id) {
return id instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier
} Prevention
- Only feed identifiers obtained from a ResolutionResult into forComponents
- Reject custom or OSGi identifiers explicitly in shared tooling
- Use configuration artifact views for file- or project-local components
When it happens
Trigger: Calling forComponents(...) with identifiers whose runtime class is neither ModuleComponentIdentifier nor ProjectComponentIdentifier — e.g. an OsgiComponentIdentifier from OSGi-resolved components, identifiers fabricated by a plugin, or non-identifier objects that slipped into the list.
Common situations: Plugins defining custom ComponentIdentifier types for virtual components; builds with OSGi/legacy Ivy machinery; code that stores ids from one Gradle version or API surface and reuses them with an ArtifactResolutionQuery.
Related errors
- Cannot query artifacts for a project component (%s).
- Cannot convert a Collection to type %s.
- Cannot convert a Map to type %s.
- Cannot specify component type multiple times.
- Must specify component type and artifacts to query.
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/2c951c4581f882bc.
Report an issue: GitHub.