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

时间:2019-12-22 10:34:45

标签: spring gradle circular-dependency multi-module subproject

我的应用程序是Gradle Multi Module Project,由多个服务和一个 service-common 模块组成。

我已经将所有模块共有的所有依赖项都放到了build.gradle根目录中,并且我还想在所有子项目中加入 service-common 模块,该模块在理论上是可行的,但我遇到了循环依赖问题,因为它本身就包含在内。

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()
}

如何排除 service-common 模块的实施项目(“:service-common”)

1 个答案:

答案 0 :(得分:2)

您可以执行以下操作:

return