在 build.gradle 文件中排除传递依赖时构建项目时出错

Error building project while excluding transitive dependency in build.gradle file

我正在使用 Spring Boot 创建一个多模块项目,用于部署我的应用程序并使用 gradle 作为我的构建工具。

现在,我正在为项目中的一些模块创建独立的部署。有些项目需要嵌入式 tomcat 而有些则不需要。所有公共依赖项都已放在一个公共项目中,所有其他模块都依赖于这个公共项目。

大多数其他部署模块需要嵌入式 tomcat 应用程序服务器和其他 Web 组件(由 org.springframework.boot 提供,名称:'spring-boot-starter-web)所以这已包含在共同项目

的 build.gradle 中

这是普通项目的build.gradle:

compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: springDataJpaVersion

现在,将要独立部署的其他模块之一不需要这个嵌入式 tomcat 和其他 mvc jar,包括 spring-boot-starter-web 但需要来自公共项目的其他传递依赖项。因此,我想排除

的传递依赖
 compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion

我在build.gradle其他项目

中就是这样做的
dependencies {
    compile project(':common') {
        exclude group 'org.springframework.boot', module:'spring-boot-starter-web'
    }
}

但是在构建时抛出了这个错误:

startup failed: build file '/Users/user1/Documents/repo/storm/build.gradle': 30: expecting '}', found ',' @ line 30, column 44. oup 'org.springframework.boot', module:'

将其更改为:

dependencies {
    compile project(':common'){
        exclude group 'org.springframework.boot:spring-boot-starter-web'
    }
}

投掷:

Could not find method exclude() for arguments [parent-project name] on project ':common'.

这里如何排除传递依赖?

您需要在 compile 而不是 project 上调用 exclude:

dependencies {
   compile(project(':common')) {
       exclude group: 'org.springframework.boot', module:'spring-boot-starter-web'
   }
}