{"record":{"id":"1e96a4ee46e1237b","repo":"gradle/gradle","slug":"the-component-filter-can-only-be-set-once-before-t","errorCode":null,"errorMessage":"The component filter can only be set once before the view was computed","messagePattern":"The component filter can only be set once before the view was computed","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/resolver/DefaultResolutionOutputs.java","lineNumber":244,"sourceCode":"        public DefaultArtifactViewConfiguration(AttributesFactory attributesFactory) {\n            this.viewAttributes = attributesFactory.mutable();\n        }\n\n        @Override\n        public AttributeContainer getAttributes() {\n            return viewAttributes;\n        }\n\n        @Override\n        public ArtifactView.ViewConfiguration attributes(Action<? super AttributeContainer> action) {\n            action.execute(viewAttributes);\n            return this;\n        }\n\n        @Override\n        public ArtifactView.ViewConfiguration componentFilter(Spec<? super ComponentIdentifier> componentFilter) {\n            if (this.componentFilter != Specs.SATISFIES_ALL) {\n                throw new IllegalStateException(\"The component filter can only be set once before the view was computed\");\n            }\n            this.componentFilter = componentFilter;\n            return this;\n        }\n\n        @Override\n        public boolean isLenient() {\n            return lenient;\n        }\n\n        @Override\n        public void setLenient(boolean lenient) {\n            this.lenient = lenient;\n        }\n\n        // TODO: Deprecate this in favor of setLenient(Boolean)\n        @Override\n        public ArtifactView.ViewConfiguration lenient(boolean lenient) {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/resolver/DefaultResolutionOutputs.java#L226-L262","documentation":"ArtifactView.ViewConfiguration.componentFilter may only be set while the filter still holds its default Specs.SATISFIES_ALL; DefaultResolutionOutputs throws IllegalStateException on any further call. Once a custom filter is installed the view configuration is considered computed with respect to filtering and cannot be re-filtered.","triggerScenarios":"Calling componentFilter(...) twice on the same ArtifactViewConfiguration — e.g. a helper method that adds a filter combined with user code that also sets one, or reusing a held view configuration object for a second filtered view.","commonSituations":"Shared utility code and user configuration both filtering the same view; plugins composing views by layering filter calls; refactors that moved filter setup into a reused closure.","solutions":["Set the filter exactly once: compose predicates (e.g. Specs.intersect / and-style combination) and pass a single Spec.","Create a fresh ArtifactView (configuration.incoming.artifactView { }) for each different filter.","Refactor helpers to accept and return a Spec rather than calling componentFilter themselves."],"exampleFix":"// before: two filter calls on one view configuration\nconfig.incoming.artifactView {\n  viewConfiguration.componentFilter(specA)\n  viewConfiguration.componentFilter(specB) // IllegalStateException\n}\n// after: compose once, or use separate views\ndef combined = org.gradle.api.specs.Specs.intersect(specA, specB)\nconfig.incoming.artifactView { viewConfiguration.componentFilter(combined) }","handlingStrategy":"validation","validationCode":"boolean filterSet = false\ndef setFilterOnce = { cfg, spec ->\n  if (filterSet) throw new IllegalStateException('componentFilter already set')\n  cfg.componentFilter(spec)\n  filterSet = true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set componentFilter once per ArtifactView; compose specs instead of calling twice.","Create a new artifactView for each different filter.","Have helpers accept/return Specs rather than mutating view configurations."],"tags":["gradle","artifact-view","api-misuse","configuration"],"backgroundTag":"double-configuration","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}