Gradle Spring Boot 2 spring-boot-dependencies无法下载依赖项

时间:2019-02-18 10:06:01

标签: spring-boot gradle

我正在使用Eclipse 2018,Gradle 5.2.1,Buildship 3.0.1。

我的配置如下:

enter image description here

我尝试根据building-spring-boot-2-projects-with-gradle创建弹簧靴2

build.gradle是:

plugins {
    id 'java'
    id 'com.gradle.build-scan' version '2.1'
    id 'org.springframework.boot' version '2.1.3.RELEASE'
}

repositories {
    jCenter()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-dependencies:2.1.3.RELEASE'
    implementation 'org.springframework.boot:spring-boot-starter-web'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    components {
        withModule('org.springframework:spring-beans') {
            allVariants {
                withDependencyConstraints {
                    // Need to patch constraints because snakeyaml is an optional dependency
                    it.findAll { it.name == 'snakeyaml' }.each { it.version { strictly '1.23' } }
                }
            }
        }
    }
}

buildScan {

    // always accept the terms of service
    termsOfServiceUrl = 'https://gradle.com/terms-of-service'
    termsOfServiceAgree = 'yes'

    // always publish a build scan
    publishAlways()
}

bootJar {
    mainClassName = 'gt4.App'
}

但是,在保存build.gradle之后,项目和外部依赖项消失了,并且也没有下载spring boot jar。

enter image description here

我怎么了?

如果我用Spring Tool Suite 4用gradle创建spring boot项目,则生成的build.gradle是:

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

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

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

然后它起作用。

我使用spring-boot-dependencies错误吗?

1 个答案:

答案 0 :(得分:0)

尝试删除本地Repository并重新构建项目以下载依赖。

删除 .m2 或 .gradle 文件夹,然后重建您的项目。

a) 在 Windows 机器上,.gradle 或 .m2 路径将是:

c:\Users\username\.m2c:\Users\username\.m2

b) 在 linux 机器上,.gradle 或 .m2 路径将是:

USER_HOME/.m2/
相关问题