gpt4 book ai didi

java - 是否有可能阻止 Gradle 添加排除的传递依赖?

转载 作者:行者123 更新时间:2023-11-30 07:39:58 24 4
gpt4 key购买 nike

我有一个使用 Gradle 5.6 构建的 Java 库,抑制了一些传递依赖

api('org.springframework.boot:spring-boot-starter-web') {
exclude module: 'spring-boot-starter-logging'
exclude module: 'spring-boot-starter-tomcat'
}

当我将它发布到 Maven 存储库时,我得到了 POM.xml

的相应部分
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
...
</dependencies>

但是当我也使用 Gradle 5.6 添加我的库作为依赖时

dependencies {
implementation 'my.group:my.lib:1.0.0'
}

我看到排除的依赖项(例如,spring-boot-starter-tomcat)出现在我的 compileClasspath 配置中。有没有办法一劳永逸地排除它,或者我应该在所有手动使用我的库的项目中这样做?

最佳答案

如文档中所述(强调我的):

Excluding a particular transitive dependency does not guarantee that it does not show up in the dependencies of a given configuration. For example, some other dependency, which does not have any exclude rules, might pull in exactly the same transitive dependency. To guarantee that the transitive dependency is excluded from the entire configuration please use per-configuration exclude rules: Configuration.getExcludeRules(). In fact, in majority of cases the actual intention of configuring per-dependency exclusions is really excluding a dependency from the entire configuration (or classpath).

您可以将规则应用于所有配置,而不是为每个配置指定排除规则:

// Kotlin DSL
configurations.all {
exclude(mapOf("module" to "spring-boot-starter-logging"))
exclude(mapOf("module" to "spring-boot-starter-tomcat"))
}

关于java - 是否有可能阻止 Gradle 添加排除的传递依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58648500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com