{"record":{"id":"2c951c4581f882bc","repo":"gradle/gradle","slug":"cannot-resolve-the-artifacts-for-component-s-with","errorCode":null,"errorMessage":"Cannot resolve the artifacts for component %s with unsupported type %s.","messagePattern":"Cannot resolve the artifacts for component (.+?) with unsupported type (.+?)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/query/DefaultArtifactResolutionQuery.java","lineNumber":196,"sourceCode":"                ComponentIdentifier validId = validateComponentIdentifier(componentId);\n                componentResults.add(buildComponentResult(validId, componentMetaDataResolver, artifactResolver));\n            } catch (Exception t) {\n                componentResults.add(new DefaultUnresolvedComponentResult(componentId, t));\n            }\n        }\n\n        return new DefaultArtifactResolutionResult(componentResults);\n    }\n\n    private ComponentIdentifier validateComponentIdentifier(ComponentIdentifier componentId) {\n        if (componentId instanceof ModuleComponentIdentifier) {\n            return componentId;\n        }\n        if (componentId instanceof ProjectComponentIdentifier) {\n            throw new IllegalArgumentException(String.format(\"Cannot query artifacts for a project component (%s).\", componentId.getDisplayName()));\n        }\n\n        throw new IllegalArgumentException(String.format(\"Cannot resolve the artifacts for component %s with unsupported type %s.\", componentId.getDisplayName(), componentId.getClass().getName()));\n    }\n\n    private ComponentArtifactsResult buildComponentResult(ComponentIdentifier componentId, ComponentMetaDataResolver componentMetaDataResolver, ArtifactResolver artifactResolver) {\n        BuildableComponentResolveResult moduleResolveResult = new DefaultBuildableComponentResolveResult();\n        componentMetaDataResolver.resolve(componentId, DefaultComponentOverrideMetadata.EMPTY, moduleResolveResult);\n        ComponentArtifactResolveMetadata component = moduleResolveResult.getState().prepareForArtifactResolution().getArtifactMetadata();\n        DefaultComponentArtifactsResult componentResult = new DefaultComponentArtifactsResult(component.getId());\n        for (Class<? extends Artifact> artifactType : artifactTypes) {\n            addArtifacts(componentResult, artifactType, component, artifactResolver);\n        }\n        return componentResult;\n    }\n\n    private <T extends Artifact> void addArtifacts(\n        DefaultComponentArtifactsResult artifacts,\n        Class<T> type,\n        ComponentArtifactResolveMetadata component,\n        ArtifactResolver artifactResolver","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/query/DefaultArtifactResolutionQuery.java#L178-L214","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nquery.forComponents(Arrays.asList(osgiId, customId)) // neither is a ModuleComponentIdentifier\n        .withArtifacts(ComponentWithModule.class, MavenModuleArtifact.class).execute()\n// after\nquery.forComponents(allIds.findAll { it instanceof ModuleComponentIdentifier })\n        .withArtifacts(ComponentWithModule.class, MavenModuleArtifact.class).execute()","handlingStrategy":"type-guard","validationCode":"def moduleIds = allIds.findAll { isQueryableComponent(it) }\ndef result = dependencies.createArtifactResolutionQuery()\n        .forComponents(moduleIds)\n        .withArtifacts(ComponentWithModule.class, MavenModuleArtifact.class).execute()","typeGuard":"static boolean isQueryableComponent(ComponentIdentifier id) {\n    return id instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["gradle","artifact-resolution-query","component-identifier","unsupported-type"],"backgroundTag":"unsupported-argument-type","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}