Occasionally, you may need to exclude specific dependencies from your Gradle project. This is especially useful when a library with unwanted transitive dependencies is included in your project.
To exclude an individual transitive dependency, use the exclude rule with both group and module specified. Here's an example:
<code class="groovy">configurations { runtime.exclude group: "org.slf4j", module: "slf4j-log4j12" }</code>
An Exclude Rule takes two attributes: group and module. By specifying both the group and module, you are precisely identifying the dependency you want to exclude.
If you attempt to specify an arbitrary property (e.g., name) in the Exclude Rule, Gradle will raise an error. This is because Exclude Rules only accept group and module properties.
In Maven, the concept of a module is equivalent to a jar. In Gradle, however, the term module is more flexible and can refer to a single artifact or a group of related artifacts (e.g., a plugin with multiple dependencies). The specific meaning of the module in a Gradle Exclude Rule will depend on the context.
<code class="groovy">dependencies { compile ('org.springframework.data:spring-data-hadoop-core:2.0.0.M4-hadoop22') { exclude group: "org.slf4j", module: "slf4j-log4j12" } }</code>
The above is the detailed content of How do I exclude specific transitive dependencies in Gradle?. For more information, please follow other related articles on the PHP Chinese website!