简体   繁体   中英

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

I have a simple multi-project structure as follows:

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

Under the root build.gradl e located in gps-framework/ looks like this:

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'
            }
        }
}

The build.gradle of sub-project gps-web-service located in gps-framework/gps-web-service looks like this:

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

From what I have read so far, since the repository settings are defined in the root build.gradle and these settings are injected into these subprojects, I do not need to redefine repository settings. This does not appear to be the case as when I run

./gradlew build

The error I get is:

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

Am I misunderstanding the whole concept of injection of project properties or what am I missing here? I will try duplicating the repo settings in the sub-projects build.gradle but was hoping this is not necessary.

To solve this specific problem, I had to define the spring boot plugin in the sub-project's build.gradle as follows:

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

The resulting file looks like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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