Home > Java > javaTutorial > body text

How to Exclude Specific Transitive Dependencies in Gradle Without Affecting Other Artifacts?

Patricia Arquette
Release: 2024-10-30 02:29:28
Original
344 people have browsed it

How to Exclude Specific Transitive Dependencies in Gradle Without Affecting Other Artifacts?

Excluding Specific Transitive Dependencies in Gradle

In Gradle, excluding transitive dependencies is crucial for managing dependencies and optimizing build performance. This question explores how to exclude all instances of a specific transitive dependency, org.slf4j:slf4j-log4j12, while preserving other necessary slf4j artifacts.

Initially, setting an exclusion using runtime.exclude group: "org.slf4j", name: "slf4j-log4j12" inadvertently excluded all slf4j artifacts. To address this, it is necessary to use module instead of name for excluding transitive dependencies, as demonstrated by:

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

This syntax effectively excludes only the specific slf4j-log4j12 module while allowing other slf4j artifacts to be included.

Furthermore, it is crucial to comprehend the concept of "module" in Gradle. Module corresponds to a particular Maven artifact. Gradle derives the module from the Maven artifacts' groupId and artifactId, following the convention:

[group]:[artifactId]
Copy after login

Therefore, for org.slf4j:slf4j-log4j12, the module is:

org.slf4j:slf4j-log4j12
Copy after login

By specifying the module, Gradle can precisely target and exclude specific transitive dependencies without affecting unrelated artifacts.

The above is the detailed content of How to Exclude Specific Transitive Dependencies in Gradle Without Affecting Other Artifacts?. 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!