spring-boot - Spring Boot无法使用Gradle Kotlin DSL解决Spring Boot的依赖关系

标签 spring-boot gradle gradle-kotlin-dsl kotlin-dsl

build.gradle.kts文件如下所示:

buildscript {
    val springBootVersion by extra("2.1.3.RELEASE")

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

plugins {
    java
    id("org.springframework.boot") version "2.1.3.RELEASE"
}

apply(plugin = "io.spring.dependency-management")

错误消息是这样的:
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all dependencies for configuration ':detachedConfiguration1'.
> Cannot resolve external dependency org.springframework.boot:spring-boot-dependencies:2.1.3.RELEASE because no repositories are defined.
 Required by:
     project :

gradle版本是:
$ ./gradlew --version

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
OS:           Linux 4.18.7-100.fc27.x86_64 amd64

常规的dsl似乎工作正常。任何帮助将不胜感激。

最佳答案

删除无用的buildscript部分,并在构建中指定存储库:

plugins {
    java
    id("org.springframework.boot") version "2.1.3.RELEASE"
}

apply(plugin = "io.spring.dependency-management")

repositories {
    mavenCentral()
}

关于spring-boot - Spring Boot无法使用Gradle Kotlin DSL解决Spring Boot的依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55051603/

相关文章:

java - SpringBoot 2迁移ConfigurationProperties无法将属性绑定(bind)到String[]

java - 为每条日志消息添加自定义值

android - 如何在 Kotlin Gradle DSL 中为多个模块重用部分 Android 配置?

Gradle - 通过配置使用项目依赖项

Spring + PostgreSQL > 多个 SLF4J 绑定(bind)

spring-boot - 分析java代码时checkstyle错误

gradle - 基于抽象类在Gradle中分离集成测试与单元测试

java - 用于单元测试的单个 gradle 工作人员

gradle - 运行任务时Gradle不会导入groovy类

Gradle 预编译脚本插件失败,第一个 block 为 `expression ... cannot be invoked as a function`