# ComponentMetadataHandler

API Documentation: | `ComponentMetadataHandler`

Allows the build to provide rules that modify the metadata of software components resolved from external repositories. Component metadata rules are applied in the components section of the dependencies block `DependencyHandler` of a build script. The rules can be defined in two different ways:

1. As an action directly when they are applied in the components section
2. As an isolated class implementing the `ComponentMetadataRule` interface

Example shows a basic way of removing certain transitive dependencies from one of our dependencies.

    plugins {
        id 'java'
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        components {
            withModule("jaxen:jaxen") {
                allVariants {
                    withDependencies {
                        removeAll { it.group in ["dom4j", "jdom", "xerces", "maven-plugins", "xml-apis", "xom"] }
                    }
                }

            }
        }
        implementation("jaxen:jaxen:1.1.3")
    }

### Properties

No properties

### Methods

Method | Description
`all(rule)` | Adds a rule closure that may modify the metadata of any resolved software component.
`all(rule)` | Adds a class based rule that may modify the metadata of any resolved software component.
`all(rule, configureAction)` | Adds a class based rule that may modify the metadata of any resolved software component. The rule itself is configured by the provided configure action.
`all(ruleSource)` | Deprecated Adds a rule that may modify the metadata of any resolved software component.
`all(rule)` | Adds a rule action that may modify the metadata of any resolved software component.
`withModule(id, rule)` | Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.
`withModule(id, rule)` | Adds a class based rule that may modify the metadata of any resolved software component belonging to the specified module.
`withModule(id, rule, configureAction)` | Adds a class based rule that may modify the metadata of any resolved software component belonging to the specified module.
`withModule(id, ruleSource)` | Deprecated Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.
`withModule(id, rule)` | Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.

### Script blocks

No script blocks

### Method details

#### `ComponentMetadataHandler` `all`(``Closure`<?>` rule)

Adds a rule closure that may modify the metadata of any resolved software component.

The supplied rule closure must declare a `ComponentMetadataDetails` as it's first parameter, allowing the component metadata to be modified.

In addition, the rule can declare additional (read-only) parameters, which may provide extra details about the component. The order of these additional parameters is not significant.

The following additional parameter types are supported:

- `IvyModuleDescriptor` - additional Ivy-specific metadata. Rules declaring this parameter will only be invoked for components packaged as an Ivy module.
- `PomModuleDescriptor` - additional Maven-specific metadata. Rules declaring this parameter will only be invoked for components packaged as a POM module.

#### `ComponentMetadataHandler` `all`(``Class`<? extends `ComponentMetadataRule`>` rule)

Adds a class based rule that may modify the metadata of any resolved software component.

#### `ComponentMetadataHandler` `all`(``Class`<? extends `ComponentMetadataRule`>` rule, ``Action`<? super `ActionConfiguration`>` configureAction)

Adds a class based rule that may modify the metadata of any resolved software component. The rule itself is configured by the provided configure action.

#### `ComponentMetadataHandler` `all`(`Object` ruleSource)

Note: This method is deprecated and will be removed in the next major version of Gradle.

Adds a rule that may modify the metadata of any resolved software component.

The ruleSource is an Object that has a single rule method annotated with `Mutate`.

This rule method:

- must return void.
- must have `ComponentMetadataDetails` as the first parameter.
- may have an additional parameter of type `IvyModuleDescriptor` or `PomModuleDescriptor`.

#### `ComponentMetadataHandler` `all`(``Action`<? super `ComponentMetadataDetails`>` rule)

Adds a rule action that may modify the metadata of any resolved software component.

#### `ComponentMetadataHandler` `withModule`(`Object` id, ``Closure`<?>` rule)

Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.

The rule closure parameter is subject to the same requirements as `ComponentMetadataHandler.all(groovy.lang.Closure)`.

#### `ComponentMetadataHandler` `withModule`(`Object` id, ``Class`<? extends `ComponentMetadataRule`>` rule)

Adds a class based rule that may modify the metadata of any resolved software component belonging to the specified module.

#### `ComponentMetadataHandler` `withModule`(`Object` id, ``Class`<? extends `ComponentMetadataRule`>` rule, ``Action`<? super `ActionConfiguration`>` configureAction)

Adds a class based rule that may modify the metadata of any resolved software component belonging to the specified module.

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

Note: This method is deprecated and will be removed in the next major version of Gradle.

Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.

The rule source parameter is subject to the same requirements as `ComponentMetadataHandler.all(java.lang.Object)`.

#### `ComponentMetadataHandler` `withModule`(`Object` id, ``Action`<? super `ComponentMetadataDetails`>` rule)

Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.