无法解析外部依赖项org.springframework.boot:spring-boot-starter:因为未定义存储库

Dre*_*208 5 gradle build.gradle spring-boot

我有multibuild项目,目前正在设置。每个模块自然都有一个gradle.build仅包含以下内容的文件:

dependencies {

}
Run Code Online (Sandbox Code Playgroud)

build.gradle我想要的主文件中,每个模块都需要。但是当我做一个gradle build我得到一个错误说:

无法解析外部依赖项org.springframework.boot:spring-boot-starter:,因为未定义存储库。要求:项目:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'

version = '0.0.1-SNAPSHOT'
    sourceCompatibility = 1.8

buildscript {
    ext {
        springBootVersion = '2.0.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {

        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

sourceSets.all { ext.purpose = null }

// Everything in subprojects are applied to all modules
subprojects {

    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'eclipse'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'

    version = '0.0.1-SNAPSHOT'


    test {
        useTestNG()
        testLogging.showStandardStreams = true

        beforeTest { descriptor ->
            logger.lifecycle("Running test: " + descriptor)
        }

        // listen to standard out and standard error of the test JVM(s)
        onOutput { descriptor, event ->
            logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
        }
    }

    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
    }

    repositories {
        jcenter()
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        compile('org.springframework.boot:spring-boot-starter')
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }

}

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)

忠告

Sta*_*lav 7

您只为子项目定义了存储库,但是您也必须在根项目中定义它,因为dependencies那里有一个块:

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)

在您的情况下,您可以通过repositoriessubprojects闭包中再次声明来做到这一点:

repositories {
    jcenter()
    mavenCentral()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}

subprojects {
   ...
}
Run Code Online (Sandbox Code Playgroud)

或者您可以为所有项目定义它:

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,您不需要o在subprojects结束时声明它