Gradle Multi Module Project:将模块依赖项应用于除自身之外的所有子项目 [英] Gradle Multi Module Project: Apply module dependency to all subprojects except for itself

查看:149
本文介绍了Gradle Multi Module Project:将模块依赖项应用于除自身之外的所有子项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My application is a Gradle Multi Module Project, consisting of multiple services with one service-common module.

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

I´ve pulled all dependencies that all modules have in common out into the root build.gradle, and I also want to include the service-common module in all subprojects, which in theory works, but I´m getting a circular dependency issue because it is included in itself.

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")?

推荐答案

您可以执行以下操作:

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

这篇关于Gradle Multi Module Project:将模块依赖项应用于除自身之外的所有子项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆