gradle/gradle · error · IllegalArgumentException

Unable to find matching strategy for {}

Error message

Unable to find matching strategy for {}

What it means

An AttributesSchema maps each Attribute to a matching strategy holding its compatibility and disambiguation rules; DefaultAttributesSchema.getMatchingStrategy throws IllegalArgumentException when the attribute was never registered via attributesSchema { attribute(...) }. The same lookup runs inside variant selection, so selecting on an undeclared attribute surfaces this error from deep within dependency resolution or any direct getMatchingStrategy call.

Source

Thrown at platforms/software/dependency-management/src/main/java/org/gradle/api/internal/attributes/DefaultAttributesSchema.java:55

    private final IsolatableFactory isolatableFactory;

    private final Map<Attribute<?>, DefaultAttributeMatchingStrategy<?>> strategies = new HashMap<>();
    private final Set<Attribute<?>> precedence = new LinkedHashSet<>();

    @Inject
    public DefaultAttributesSchema(InstantiatorFactory instantiatorFactory, IsolatableFactory isolatableFactory) {
        this.instantiatorFactory = instantiatorFactory;
        this.isolatableFactory = isolatableFactory;
    }

    // region public API

    @Override
    @SuppressWarnings("unchecked")
    public <T> AttributeMatchingStrategy<T> getMatchingStrategy(Attribute<T> attribute) {
        AttributeMatchingStrategy<T> strategy = (DefaultAttributeMatchingStrategy<T>) strategies.get(attribute);
        if (strategy == null) {
            throw new IllegalArgumentException("Unable to find matching strategy for " + attribute);
        }
        return strategy;
    }

    @Override
    public <T> AttributeMatchingStrategy<T> attribute(Attribute<T> attribute) {
        return attribute(attribute, null);
    }

    @Override
    public <T> AttributeMatchingStrategy<T> attribute(Attribute<T> attribute, @Nullable Action<? super AttributeMatchingStrategy<T>> configureAction) {
        AttributeMatchingStrategy<T> strategy = getStrategy(attribute);
        if (configureAction != null) {
            configureAction.execute(strategy);
        }
        return strategy;
    }

View on GitHub (pinned to 534f27719b)

Solutions

  1. Declare the attribute before any use: dependencies.attributesSchema { attribute(MyAttribute) } in every project that selects on it (or via a convention plugin applied to all)
  2. Plugin authors: register the attribute in the schema when the plugin is applied
  3. Ensure name AND type of the Attribute instance match exactly between declaration and usage sites

Example fix

// before
def OPT = Attribute.of('pkg.optimization', String)
configurations.runtimeClasspath { attributes { attribute(OPT, 'size') } } // never declared -> error

// after
def OPT = Attribute.of('pkg.optimization', String)
dependencies.attributesSchema { attribute(OPT) }
configurations.runtimeClasspath { attributes { attribute(OPT, 'size') } }
Defensive patterns

Strategy: validation

Validate before calling

// guard any strategy lookup / attribute use with a schema registration check
def schema = project.dependencies.attributesSchema
if (!schema.hasAttribute(MyAttribute)) {
    schema.attribute(MyAttribute)   // or throw, if the attribute must already be declared elsewhere
}
def strategy = schema.getMatchingStrategy(MyAttribute)

Prevention

When it happens

Trigger: Calling dependencies.attributesSchema.getMatchingStrategy(MyAttribute) before declaring attributesSchema.attribute(MyAttribute); a plugin setting configuration/consumer attributes (attributes { attribute(CUSTOM, ...) }) in a project whose schema never registered that attribute; an attribute with a slightly different name or type than the registered instance so the map lookup misses.

Common situations: Convention applied to the root project but the attribute used in subprojects (schemas are per-project); plugin sets attributes without registering the schema entry; Attribute.of('custom.name', String) vs Attribute.of('custom.Name', String) mismatches after refactor.

Related errors


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