Home > Java > javaTutorial > body text

How do I exclude specific transitive dependencies in Gradle?

Barbara Streisand
Release: 2024-10-26 08:23:30
Original
993 people have browsed it

How do I exclude specific transitive dependencies in Gradle?

How to Exclude Transitive Dependencies with Gradle

Background

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.

Solution

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>
Copy after login

Explanation

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.

Maven Module vs. Gradle Module

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.

Additional Notes

  • To exclude a dependency from a specific individual dependency, use the following syntax:
<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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!