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

  1. Point at a resolvable configuration such as runtimeClasspath or a configurations.resolvable(...) one
  2. If the intended source is declarable, add a resolvable configuration extending it and use that
  3. 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

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


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