# ComponentSelectionRules

API Documentation: | `ComponentSelectionRules`

Note: This class is incubating and may change in a future version of Gradle.

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, IvyModuleDescriptor descriptor, ComponentMetadata metadata ->
                        if (selection.candidate.module == 'someModule' && descriptor.branch == 'testing') {
                            if (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")
                        }
                    }
                }
            }
        }
    }

### Properties

No properties

### Methods

Method | Description
`all(closure)` | Incubating Adds a component selection rule that will apply to all resolved components. Each rule will receive a `ComponentSelection` object as an argument as well as any other arguments specified for the closure. Allowable closure arguments are `ComponentSelection` (required), `ComponentMetadata` and/or `IvyModuleDescriptor`.
`all(ruleSource)` | Incubating Adds a rule-source backed component selection rule that will apply to all resolved components. The ruleSource provides the rule as exactly one rule method annotated with `Mutate`. This rule method:
`all(selectionAction)` | Incubating Adds a simple component selection rule that will apply to all resolved components. Each rule will receive a `ComponentSelection` object as an argument.
`withModule(id, closure)` | Incubating Adds a component selection rule that will apply to the specified module. Each rule will receive a `ComponentSelection` object as an argument as well as any other arguments specified for the closure. Allowable closure arguments are `ComponentSelection` (required), `ComponentMetadata` and/or `IvyModuleDescriptor`.
`withModule(id, ruleSource)` | Incubating Adds a rule-source backed component selection rule that will apply to the specified module. The ruleSource provides the rule as exactly one rule method annotated with `Mutate`. This rule method:
`withModule(id, selectionAction)` | Incubating Adds a component selection rule that will apply to the specified module. Each rule will receive a `ComponentSelection` object as an argument.

### Script blocks

No script blocks

### Method details

#### `ComponentSelectionRules` `all`(``Closure`<?>` closure)

Note: This method is incubating and may change in a future version of Gradle.

Adds a component selection rule that will apply to all resolved components. Each rule will receive a `ComponentSelection` object as an argument as well as any other arguments specified for the closure. Allowable closure arguments are `ComponentSelection` (required), `ComponentMetadata` and/or `IvyModuleDescriptor`.

#### `ComponentSelectionRules` `all`(`Object` ruleSource)

Note: This method is incubating and may change in a future version of Gradle.

Adds a rule-source backed component selection rule that will apply to all resolved components. The ruleSource provides the rule as exactly one rule method annotated with `Mutate`. This rule method:

- must return void.
- must have `ComponentSelection` as the first parameter.
- may have additional parameters of type `ComponentMetadata` and/or `IvyModuleDescriptor`.

#### `ComponentSelectionRules` `all`(``Action`<? super `ComponentSelection`>` selectionAction)

Note: This method is incubating and may change in a future version of Gradle.

Adds a simple component selection rule that will apply to all resolved components. Each rule will receive a `ComponentSelection` object as an argument.

#### `ComponentSelectionRules` `withModule`(`Object` id, ``Closure`<?>` closure)

Note: This method is incubating and may change in a future version of Gradle.

Adds a component selection rule that will apply to the specified module. Each rule will receive a `ComponentSelection` object as an argument as well as any other arguments specified for the closure. Allowable closure arguments are `ComponentSelection` (required), `ComponentMetadata` and/or `IvyModuleDescriptor`.

#### `ComponentSelectionRules` `withModule`(`Object` id, `Object` ruleSource)

Note: This method is incubating and may change in a future version of Gradle.

Adds a rule-source backed component selection rule that will apply to the specified module. The ruleSource provides the rule as exactly one rule method annotated with `Mutate`. This rule method:

- must return void.
- must have `ComponentSelection` as the first parameter.
- may have additional parameters of type `ComponentMetadata` and/or `IvyModuleDescriptor`.

#### `ComponentSelectionRules` `withModule`(`Object` id, ``Action`<? super `ComponentSelection`>` selectionAction)

Note: This method is incubating and may change in a future version of Gradle.

Adds a component selection rule that will apply to the specified module. Each rule will receive a `ComponentSelection` object as an argument.