Не удается разрешить внешнюю зависимость org.springframework.boot: spring-boot-starter: потому что репозитории не определены

У меня есть проект с несколькими сборками, и я сейчас только настраиваю его. Каждый модуль, естественно, имеет gradle.build файл, который содержит только следующее:

dependencies {

}

В основном build.gradle файле, который мне нужен, нужен для каждого модуля. Однако когда я делаю gradle build, я получаю сообщение об ошибке:

Не удается разрешить внешнюю зависимость org.springframework.boot: spring-boot-starter: потому что не определены репозитории. Требуется: project:

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

Совет


person Mike3355    schedule 04.04.2018    source источник


Ответы (1)


Вы определили репозитории только для подпроектов, но вы также должны определить его в корневом проекте, потому что там у вас есть блок dependencies:

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

В вашем случае вы можете сделать это, еще раз объявив repositories вне subprojects закрытия:

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

subprojects {
   ...
}

Или вы можете определить его для всех проектов:

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

в этом случае вам не нужно объявлять это в subprojects закрытии

person Stanislav    schedule 04.04.2018