Home > Java > javaTutorial > body text

How to Exclude Specific Transitive Dependencies in Gradle: A Solution for Excluding slf4j-log4j12

Patricia Arquette
Release: 2024-10-26 18:35:30
Original
373 people have browsed it

How to Exclude Specific Transitive Dependencies in Gradle:  A Solution for Excluding slf4j-log4j12

Excluding Specific Dependencies During Gradle Build

Gradle allows excluding specific transitive dependencies to avoid unwanted artifacts in your built jar files. In this article, we'll explore how to exclude org.slf4j:slf4j-log4j12 using Gradle configurations.

Problem Statement

A Gradle project using the application plugin encountered challenges excluding slf4j-log4j12 from its runtime dependencies. Initial attempts to exclude it using the runtime.exclude configuration excluded all org.slf4j artifacts, including slf4j-api.

Solution

To resolve the issue, use the following syntax to specify both the group and module:

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

This approach ensures the exclusion of only the desired dependency, leaving other org.slf4j artifacts unaffected.

Additional Notes

When excluding from an individual dependency, only the group and module properties are available as predicates. Unlike dependency declarations, you cannot specify arbitrary properties such as name.

The concept of a "module" in Gradle aligns with the Maven notion of artifactId. In the example above, slf4j-log4j12 represents the module. To determine the module name for a Maven artifact, refer to its artifactId component.

The above is the detailed content of How to Exclude Specific Transitive Dependencies in Gradle: A Solution for Excluding slf4j-log4j12. 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