# ComponentMetadataHandler

@ServiceScope(value = Project::class)
interface ComponentMetadataHandler(source)

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")
    }

Content copied to clipboard

#### Since

1.8

## Functions

all
Link copied to clipboard
abstract fun all(@DelegatesTo(value = ComponentMetadataDetails::class) rule: Closure<out Any>): ComponentMetadataHandler
Adds a rule closure that may modify the metadata of any resolved software component.
abstract fun all(rule: Class<out ComponentMetadataRule>): ComponentMetadataHandler
abstract fun all(rule: Class<out ComponentMetadataRule>, configureAction: Action<in ActionConfiguration>): ComponentMetadataHandler
Adds a class based rule that may modify the metadata of any resolved software component.
abstract fun all(ruleSource: Any): ComponentMetadataHandler
Adds a rule that may modify the metadata of any resolved software component.
abstract fun all(rule: Action<in ComponentMetadataDetails>): ComponentMetadataHandler
Adds a rule action that may modify the metadata of any resolved software component.
all
Link copied to clipboard
inline fun <T : ComponentMetadataRule> ComponentMetadataHandler.all(): ComponentMetadataHandler

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

inline fun ComponentMetadataHandler.all(rule: KClass<out ComponentMetadataRule>): ComponentMetadataHandler
inline fun ComponentMetadataHandler.all(rule: KClass<out ComponentMetadataRule>, configureAction: Action<in ActionConfiguration>): ComponentMetadataHandler

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.artifacts.dsl.ComponentMetadataHandler.all.

inline fun <T : ComponentMetadataRule> ComponentMetadataHandler.all(configureAction: Action<in ActionConfiguration>): ComponentMetadataHandler

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.

withModule
Link copied to clipboard
abstract fun withModule(id: Any, @DelegatesTo(value = ComponentMetadataDetails::class) rule: Closure<out Any>): ComponentMetadataHandler
abstract fun withModule(id: Any, ruleSource: Any): ComponentMetadataHandler
abstract fun withModule(id: Any, rule: Action<in ComponentMetadataDetails>): ComponentMetadataHandler
Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.
abstract fun withModule(id: Any, rule: Class<out ComponentMetadataRule>): ComponentMetadataHandler
abstract fun withModule(id: Any, rule: Class<out ComponentMetadataRule>, configureAction: Action<in ActionConfiguration>): ComponentMetadataHandler
Adds a class based rule that may modify the metadata of any resolved software component belonging to the specified module.
withModule
Link copied to clipboard
inline fun <T : ComponentMetadataRule> ComponentMetadataHandler.withModule(id: Any): ComponentMetadataHandler
inline fun <T : ComponentMetadataRule> ComponentMetadataHandler.withModule(id: Any, configureAction: Action<in ActionConfiguration>): ComponentMetadataHandler

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

inline fun ComponentMetadataHandler.withModule(id: Any, rule: KClass<out ComponentMetadataRule>): ComponentMetadataHandler
inline fun ComponentMetadataHandler.withModule(id: Any, rule: KClass<out ComponentMetadataRule>, configureAction: Action<in ActionConfiguration>): ComponentMetadataHandler

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.artifacts.dsl.ComponentMetadataHandler.withModule.