gradle
8.3

# ComponentSelectionRules

interface ComponentSelectionRules

Represents a container for component selection rules. Rules can be applied as part of the resolutionStrategy of a configuration and individual components can be explicitly accepted or rejected by rule. Components that are neither accepted or rejected will be subject to the default version matching strategies.

        configurations {
            conf {
                resolutionStrategy {
                    componentSelection {
                        all { ComponentSelection selection ->
                            if (selection.candidate.module == 'someModule' && selection.candidate.version == '1.1') {
                                selection.reject("bad version '1.1' for 'someModule'")
                            }
                        }
                        all { ComponentSelection selection ->
                            if (selection.candidate.module == 'someModule' && selection.getDescriptor(IvyModuleDescriptor)?.branch == 'testing') {
                                if (selection.metadata == null || selection.metadata.status != 'milestone') {
                                    selection.reject("only use milestones for someModule:testing")
                                }
                            }
                        }
                        withModule("org.sample:api") { ComponentSelection selection ->
                            if (selection.candidate.version == "1.1") {
                                selection.reject("known bad version")
                            }
                        }
                    }
                }
            }
        }

Content copied to clipboard

## Functions

all
Link copied to clipboard
abstract fun all(@DelegatesTo(value = ComponentSelection::class) closure: Closure<out Any>): ComponentSelectionRules
Adds a component selection rule that will apply to all resolved components.
abstract fun all(ruleSource: Any): ComponentSelectionRules
Adds a rule-source backed component selection rule that will apply to all resolved components.
abstract fun all(selectionAction: Action<out Any>): ComponentSelectionRules
Adds a simple component selection rule that will apply to all resolved components.
withModule
Link copied to clipboard
abstract fun withModule(id: Any, @DelegatesTo(value = ComponentSelection::class) closure: Closure<out Any>): ComponentSelectionRules
abstract fun withModule(id: Any, selectionAction: Action<out Any>): ComponentSelectionRules
Adds a component selection rule that will apply to the specified module.
abstract fun withModule(id: Any, ruleSource: Any): ComponentSelectionRules
Adds a rule-source backed component selection rule that will apply to the specified module.