api / org.gradle.api.attributes / DisambiguationRuleChain

DisambiguationRuleChain

@Incubating interface DisambiguationRuleChain<T : Any>

A chain of disambiguation rules. By default the chain is empty and will not do any disambiguation.

For a given set of rules, the execution is done in order, and interrupts as soon as a rule selected at least one candidate (through MultipleCandidatesDetails#closestMatch(Object)).

If the end of the rule chain is reached and that no rule selected a candidate then the candidate list is returned unmodified, meaning we still have an ambiguous match.

Parameters

- the concrete type of the attribute

Functions

add

abstract fun add(rule: Class<out AttributeDisambiguationRule<T>>): Unit

Adds an arbitrary disambiguation rule to the chain.

A disambiguation rule can select the best match from a list of candidates.

A rule can express an preference by calling the @{link MultipleCandidatesDetails#closestMatch(Object) method to tell that a candidate is the best one.

It is not mandatory for a rule to choose, and it is not an error to select multiple candidates.

abstract fun add(rule: Class<out AttributeDisambiguationRule<T>>, configureAction: Action<in ActionConfiguration>): Unit

Adds an arbitrary disambiguation rule to the chain, possibly configuring the rule as well.

pickFirst

abstract fun pickFirst(comparator: Comparator<in T>): Unit

Adds an ordered disambiguation rule. Values will be compared using the provided comparator, and the rule will automatically select the first value (if multiple candidates have the same attribute value, there will still be an ambiguity).

pickLast

abstract fun pickLast(comparator: Comparator<in T>): Unit

Adds an ordered disambiguation rule. Values will be compared using the provided comparator, and the rule will automatically select the last value (if multiple candidates have the same attribute value, there will still be an ambiguity).