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 artifactResolver

View on GitHub (pinned to 534f27719b)

Solutions

  1. Pass only real ModuleComponentIdentifier instances into forComponents(...) — best obtained from a ResolutionResult.
  2. Filter unknown ids out: keep only ids where id instanceof ModuleComponentIdentifier.
  3. 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

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


AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22). Data as JSON: /api/errors/2c951c4581f882bc. Report an issue: GitHub.