首页 > 解决方案 > gradle 从运行时依赖项中排除特定的 jar

问题描述

有没有办法使用 Gradle 从组中排除特定的罐子?我试过下面的代码,但这删除了该组的所有罐子

configurations {
   all*.exclude group: 'org.xxxx.xxxx'
}

我的要求是只从组中删除特定的罐子,而不是所有罐子。我们正在做这个练习来排除系统运行时的传递依赖。

谢谢。

标签: javagradlebuild.gradledependency-management

解决方案


您可以在依赖项块中排除组中的所有依赖项,或仅排除组中的某些模块:

    dependencies {

        /* --------------  SpringBoot without Tomcat  ------------------- */
        compile('org.springframework.boot:spring-boot-starter-web') {    
            exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
        }

    }

我添加了指向 Gradle 文档的链接,详细解释了传递依赖项:https ://docs.gradle.org/current/userguide/managing_transitive_dependencies.html


推荐阅读