使用SpringBoot和Gradle出现问题,无法开始

8

我是一个Java、Gradle和Spring的新手。

我用以下Gradle脚本设置了一个新项目:

buildscript {
    repositories {
        maven { url "http://repo.spring.io/snapshot" }
        maven { url "http://repo.spring.io/milestone" }
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT")
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

repositories {
    maven { url "http://repo.spring.io/snapshot" }
    maven { url "http://repo.spring.io/milestone" }
}

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

尝试使用上述脚本构建时,我遇到了以下错误:
E:\Projects\SpringAppTutorial>gradlew

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'SpringAppTutorial'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT.
    Required by:
        :SpringAppTutorial:unspecified
     > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.3.0.BUILD-SNAPSHOT.
        > Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-gradle-plugin/1.3.0.BUILD-SNAPSHOT/spring-boot-gradle-plugin-1.3.0.BUILD-20150531.081700-179.pom
           > Could not resolve org.springframework.boot:spring-boot-tools:1.3.0.BUILD-SNAPSHOT.
              > Could not resolve org.springframework.boot:spring-boot-tools:1.3.0.BUILD-SNAPSHOT.
                 > Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-tools/1.3.0.BUILD-SNAPSHOT/spring-boot-tools-1.3.0.BUILD-20150531.081700-180.pom
                    > Could not resolve org.springframework.boot:spring-boot-parent:1.3.0.BUILD-SNAPSHOT.
                       > Could not resolve org.springframework.boot:spring-boot-parent:1.3.0.BUILD-SNAPSHOT.
                          > Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-parent/1.3.0.BUILD-SNAPSHOT/spring-boot-parent-1.3.0.BUILD-20150531.081700-180.pom
                             > Could not resolve org.springframework.boot:spring-boot-dependencies:1.3.0.BUILD-SNAPSHOT.
                                > Could not resolve org.springframework.boot:spring-boot-dependencies:1.3.0.BUILD-SNAPSHOT.
                                   > Could not parse POM http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-dependencies/1.3.0.BUILD-SNAPSHOT/spring-boot-dependencies-1.3.0.BUILD-20150531.081700-181.pom
                                      > Could not find org.springframework.data:spring-data-releasetrain:Fowler-RELEASE.
                                        Searched in the following locations:
                                            http://repo.spring.io/snapshot/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.pom
                                            http://repo.spring.io/snapshot/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.jar
                                            http://repo.spring.io/milestone/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.pom
                                            http://repo.spring.io/milestone/org/springframework/data/spring-data-releasetrain/Fowler-RELEASE/spring-data-releasetrain-Fowler-RELEASE.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 15.726 secs

E:\Projects\SpringAppTutorial>

我在这里做错了什么?

2个回答

7

您应该使用发布版本的spring-boot gradle插件,您的脚本正在使用某种开发快照版本字符串。

例如,请尝试

dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}

(来自http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html

假设这样可以,你也应该能够摆脱这个部分:

repositories {
   maven { url "http://repo.spring.io/snapshot" }
   maven { url "http://repo.spring.io/milestone" }
}

1
我必须从仓库列表中删除repo.spring.io/snapshot repos,只保留repo.spring.io/release repo。我还必须将mavenCentral()添加到仓库列表中,因为它无法找到其他标准库,例如logging。这些更改都修复了构建问题。感谢您指引我正确的方向。 - balajeerc

0

我曾经遇到过同样的问题,正如@skaffman所建议的那样,我在我的依赖项中添加了版本,问题得到了解决。

implementation('org.springframework.session:spring-session:1.3.4.RELEASE')
 runtimeOnly('com.okta.spring:okta-spring-boot-starter:0.6.1')
 runtimeOnly('org.springframework.security.oauth:spring-security-oauth2:2.3.4.RELEASE')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接