gradle/gradle · error · UnsupportedOperationException
Cannot set '%s' in '%s' as it is a filtered collection
Error message
Cannot set '%s' in '%s' as it is a filtered collection
What it means
shouldResolveConsistentlyWith(source) makes this configuration resolve against the source's resolved state so both see identical versions. assertThatConsistentResolutionIsPropertyConfigured requires the source to be resolvable (isCanBeResolved) and throws InvalidUserCodeException naming both configurations when it is not.
Source
Thrown at platforms/core-configuration/domain-object-collections/src/main/java/org/gradle/api/internal/collections/FilteredIndexedElementSource.java:50
@Override
public S get(int index) {
int nextIndex = 0;
for (T t : collection) {
S s = filter.filter(t);
if (s != null) {
if (nextIndex == index) {
return s;
}
nextIndex++;
}
}
throw new IndexOutOfBoundsException();
}
@Override
public S set(int index, S element) {
throw new UnsupportedOperationException(String.format("Cannot set '%s' in '%s' as it is a filtered collection", element, this));
}
@Override
public S remove(int index) {
throw new UnsupportedOperationException(String.format("Cannot remove element from '%s' as it is a filtered collection", this));
}
@Override
public int indexOf(Object o) {
int nextIndex = 0;
for (T t : collection) {
S s = filter.filter(t);
if (s != null) {
if (s.equals(o)) {
return nextIndex;
}
nextIndex++;
}View on GitHub (pinned to 534f27719b)
Solutions
- Point at a resolvable configuration such as runtimeClasspath or a configurations.resolvable(...) one
- If the intended source is declarable, add a resolvable configuration extending it and use that
- Validate source.isCanBeResolved() before wiring
Example fix
// before
configurations {
testRuntimeClasspath.shouldResolveConsistentlyWith(configurations.implementation) // not resolvable
}
// after
configurations {
testRuntimeClasspath.shouldResolveConsistentlyWith(configurations.runtimeClasspath)
} Defensive patterns
Strategy: validation
Validate before calling
if (!source.isCanBeResolved()) {
throw new GradleException("${source.name} is not resolvable; use a resolvable source such as runtimeClasspath")
}
target.shouldResolveConsistentlyWith(source) Prevention
- Remember consistent-resolution sources must themselves be resolvable
- Wire classpath to classpath (testRuntimeClasspath -> runtimeClasspath)
- Centralize this wiring in a convention plugin where configuration roles are known
When it happens
Trigger: configurations.testRuntimeClasspath.shouldResolveConsistentlyWith(configurations.implementation) where implementation is declarable-only; wiring a consumable configuration as the consistent-resolution source.
Common situations: Trying to keep test and main runtime classpaths version-consistent while pointing at a non-resolvable configuration; plugin code guessing a source configuration name.
Related errors
- Cannot add a %s with name '%s' as a %s with that name alread
- Cannot register a factory for type %s because a factory for
- Cannot remove element from '%s' as it is a filtered collecti
- Expected %s to contain exactly one file, however, it contain
- Expected %s to contain exactly one file, however, it contain
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/df5ae878fc79a89a.
Report an issue: GitHub.