Gradle 多模块项目:将模块依赖项应用于除自身之外的所有子项目



我的应用程序是一个 Gradle 多模块项目,由多个服务组成,其中包含一个服务通用模块。

我已经将所有模块共有的所有依赖项拉到根 build.gradle 中,我还想在所有子项目中包含服务公共模块,这在理论上是有效的,但我遇到了循环依赖项问题,因为它包含在自身中。

apply plugin: 'java'
group = 'com.myapplication'
ext {
set('springCloudVersion', "2.2.0.RELEASE")
set('springBootVersion', "2.2.2.RELEASE")
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
}
buildscript {
ext {
springBootVersion = "2.2.2.RELEASE"
}
repositories {
maven { url 'https://repo.spring.io/plugins-snapshot' }
jcenter()
mavenCentral()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.7.BUILD-SNAPSHOT'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
version = '1.0'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
apply plugin: 'java'
ext {
springCloudVersion = "2.2.0.RELEASE"
springBootVersion = "2.2.2.RELEASE"
}
test {
useJUnitPlatform()
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://repo.spring.io/milestone' }
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "${springBootVersion}"
compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: "${springBootVersion}"
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter', version: "${springCloudVersion}"
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-kubernetes', version: '1.1.1.RELEASE'
compile group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.3.2'
compile group: 'com.github.piomin', name: 'logstash-logging-spring-boot-starter', version: '1.2.2.RELEASE'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.9'
testCompile group: 'org.springframework.cloud', name: 'spring-cloud-stream-test-support', version: "${springCloudVersion}"
implementation project(":service-common")
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}

如何排除服务通用模块的实现项目(":服务通用"(

你可以执行以下操作:

subprojects {
dependencies {
if (!project.name == "service-common") {
implementation(project(":service-common"))
}
}
}

相关内容

  • 没有找到相关文章

最新更新