gradle/gradle · error · IllegalStateException
The component filter can only be set once before the view wa
Error message
The component filter can only be set once before the view was computed
What it means
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.
Source
Thrown at platforms/software/dependency-management/src/main/java/org/gradle/api/internal/artifacts/resolver/DefaultResolutionOutputs.java:244
public DefaultArtifactViewConfiguration(AttributesFactory attributesFactory) {
this.viewAttributes = attributesFactory.mutable();
}
@Override
public AttributeContainer getAttributes() {
return viewAttributes;
}
@Override
public ArtifactView.ViewConfiguration attributes(Action<? super AttributeContainer> action) {
action.execute(viewAttributes);
return this;
}
@Override
public ArtifactView.ViewConfiguration componentFilter(Spec<? super ComponentIdentifier> componentFilter) {
if (this.componentFilter != Specs.SATISFIES_ALL) {
throw new IllegalStateException("The component filter can only be set once before the view was computed");
}
this.componentFilter = componentFilter;
return this;
}
@Override
public boolean isLenient() {
return lenient;
}
@Override
public void setLenient(boolean lenient) {
this.lenient = lenient;
}
// TODO: Deprecate this in favor of setLenient(Boolean)
@Override
public ArtifactView.ViewConfiguration lenient(boolean lenient) {View on GitHub (pinned to 534f27719b)
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.
Example fix
// before: two filter calls on one view configuration
config.incoming.artifactView {
viewConfiguration.componentFilter(specA)
viewConfiguration.componentFilter(specB) // IllegalStateException
}
// after: compose once, or use separate views
def combined = org.gradle.api.specs.Specs.intersect(specA, specB)
config.incoming.artifactView { viewConfiguration.componentFilter(combined) } Defensive patterns
Strategy: validation
Validate before calling
boolean filterSet = false
def setFilterOnce = { cfg, spec ->
if (filterSet) throw new IllegalStateException('componentFilter already set')
cfg.componentFilter(spec)
filterSet = true
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Setting the working directory of a worker is not supported.
- Cannot parse memory amount notation:
- No main class specified and classpath is not an executable j
- Running a Java module is not supported in this context.
- Cannot parse heap size: {heapSize}
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/1e96a4ee46e1237b.
Report an issue: GitHub.