繁体   English   中英

Gradle 多项目存储库配置不适用于 spring-boot 应用程序

[英]Gradle multi-project repository configuration not working for spring-boot application

我有一个简单的多项目结构如下:

|- gps-framework
|- build.gradle
|- settings.gradle
|- gps-web-service
|----build.gradle
|----src/main....

在位于gps-framework/根目录下的build.gradl e 看起来像这样:

plugins {
    id 'java'
    id "java-library"
    id "maven-publish"
    id "jacoco"
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}

subprojects {

    subproject ->
        
        apply plugin: 'maven-publish'
        apply plugin: 'jacoco'
      
        def isApp = subproject.name == 'gps-web-service'

        if (isApp) {
            apply plugin: 'java'
        } else {
            apply plugin: 'java-library'
        }

        group = 'com.mycompnay'
        version = project.hasProperty('customVersion') ? project['customVersion'] : 'integration-SNAPSHOT'

        //System.out.println(subproject.name)

        compileJava {
            sourceCompatibility = '1.8'
            targetCompatibility = '1.8'

            options.encoding = 'UTF-8'
     
        }

        compileTestJava {
            sourceCompatibility = '1.8'
            targetCompatibility = '1.8'

            options.encoding = 'UTF-8'

        }

        repositories {
            mavenCentral()
            mavenLocal()

            maven {
                name "release"
                url "my-custom-mvn-repo/release"
                authentication {
                    //
                }
            }

            maven {
                name "snapshot"
                url "my-custoom-mvn-repo/snapshot"
                authentication {
                    //
                }
            }
        }

        configurations {
            runtime.exclude(group: "org.slf4j", module:"slf4j-log4j12")
        }

        publishing {
            repositories {
                maven {
                    authentication {
                        //
                    }
                    def isSnapshot = subproject.version.contains('SNAPSHOT')
                    url =  isSnapshot ? "my-custom-mvn-repo/snapshot" : "my-custom-mnv-repo/release"
                }
            }
        }

        jacocoTestReport {
            reports {
                xml.enabled true
                html.enabled true
            }
        }

        if (subproject.hasProperty('jacocoTestCoverageVerification')) {
            subproject.check.dependsOn subproject.jacocoTestCoverageVerification
        }

        test {
            testLogging {
                exceptionFormat = 'full'
            }
        }
}

位于gps-framework/gps-web-service的子项目 gps-web-service 的build.gradle如下所示:

group = 'com.mycompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'


dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

从我到目前为止所读到的内容来看,由于存储库设置是在根 build.gradle 中定义的,并且这些设置被注入到这些子项目中,因此我不需要重新定义存储库设置。 这似乎不像我跑步时的情况

./gradlew build

我得到的错误是:

Could not find org.springframework.boot:spring-boot-starter-web:.
Required by:
    project :gps-web-service

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

我是否误解了注入项目属性的整个概念,或者我在这里遗漏了什么? 我将尝试复制子项目 build.gradle 中的 repo 设置,但希望这不是必需的。

为了解决这个特定的问题,我不得不在子项目的 build.gradle 中定义 spring boot 插件如下:

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}

生成的文件如下所示:

plugins {
        id 'org.springframework.boot' version '2.3.4.RELEASE'
        id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    }

group = 'com.mycompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'


dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM