Interface ComponentMetadataHandler


@ServiceScope(org.gradle.internal.service.scopes.Scope.Project.class) public interface ComponentMetadataHandler
Allows the build to provide rules that modify the metadata of depended-on software components. 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")
 }
 
Since:
1.8