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

2024-02-23

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

dependencies {

}

在主要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')
}

Advice


您仅为子项目定义了存储库,但您也必须在根项目中定义它,因为您有一个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 closure

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法解析外部依赖 org.springframework.boot:spring-boot-starter: 因为没有定义存储库 的相关文章

随机推荐