Java 是否可以防止Gradle添加排除的传递依赖项?
我使用Gradle 5.6构建了一个Java库,并抑制了一些可传递的依赖项Java 是否可以防止Gradle添加排除的传递依赖项?,java,gradle,Java,Gradle,我使用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 repo时,我得到了POM.xml <dependencies>
api('org.springframework.boot:spring-boot-starter-web') {
exclude module: 'spring-boot-starter-logging'
exclude module: 'spring-boot-starter-tomcat'
}
当我将它发布到Maven repo时,我得到了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>
我在compileClasspath
配置中看到了排除的依赖项(例如,spring boot starter tomcat
)。有没有办法一劳永逸地排除它,或者我应该在所有手动使用我的库的项目中都这样做 如文件中所述(重点):
排除特定的可传递依赖项并不保证它不会出现在给定配置的依赖项中。例如,没有任何排除规则的其他依赖项可能会拉入完全相同的传递依赖项为保证可传递依赖项从整个配置中排除,请使用每个配置排除规则:configuration.getExcludeRules()。事实上,在大多数情况下,配置每个依赖项排除的实际意图实际上是从整个配置(或类路径)中排除依赖项
您可以将规则应用于所有配置,而不是为每个配置指定排除规则:
// Kotlin DSL
configurations.all {
exclude(mapOf("module" to "spring-boot-starter-logging"))
exclude(mapOf("module" to "spring-boot-starter-tomcat"))
}
当您列出带有
gradle-q依赖项的依赖项时
是否看到spring boot starter tomcat
被my.lib
拉入?是的,它同时出现在compileClasspath
和运行时
配置中
// Kotlin DSL
configurations.all {
exclude(mapOf("module" to "spring-boot-starter-logging"))
exclude(mapOf("module" to "spring-boot-starter-tomcat"))
}