Home  >  Article  >  Java  >  How to Exclude Specific Transitive Dependencies in Gradle Using the \"module\" Parameter?

How to Exclude Specific Transitive Dependencies in Gradle Using the \"module\" Parameter?

DDD
DDDOriginal
2024-10-26 02:48:02514browse

How to Exclude Specific Transitive Dependencies in Gradle Using the

How to Selectively Exclude Transitive Dependencies in Gradle

When building a project with Gradle, it's possible for the application plugin to bring in unwanted transitive dependencies, such as org.slf4j:slf4j-log4j12. Using the traditional exclude rule with only group and name parameters may result in excluding too many artifacts or even entire configurations.

The Solution: Using module Parameter

To specifically exclude an individual artifact without affecting other dependencies, use the following syntax:

configurations {
  runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}

The module parameter in ExcludeRule specifies the artifact that should be excluded. It's important to note that name cannot be used in an exclusion with module.

Excluding from Individual Dependencies

To exclude a specific transitive dependency from a particular dependency, use the following approach:

dependencies {
  compile ('org.springframework.data:spring-data-hadoop-core:2.0.0.M4-hadoop22') {
    exclude group: "org.slf4j", module: "slf4j-log4j12"
  }
}

Understanding Modules in Gradle

In Gradle, a module refers to a specific artifact within a dependency. It doesn't have a direct mapping to the Maven concept of modules. To determine the module of a Maven artifact, refer to the artifact's Maven coordinates in the Maven Central repository, which typically includes information like groupId, artifactId, and version.

The above is the detailed content of How to Exclude Specific Transitive Dependencies in Gradle Using the \"module\" Parameter?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn