0

我是 Gradle 的新手,我按照教程的说明进行操作,只是我在 Spring.Initializr 中选择了 Gradle 而不是 maven。

它为 build.gradle 生成了以下代码

plugins {
    id 'org.springframework.boot' version '2.6.3'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.microservicetest'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

ext {
    set('springCloudVersion', "2021.0.0")
}

// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies
import group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: '2021.0.0', ext: 'pom'


dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.cloud:spring-cloud-config-server'
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

tasks.named('test') {
    useJUnitPlatform()
}

我收到错误消息

Could not compile build file '/home/max/IdeaProjects/Restaurant Rating App/build.gradle'.
> startup failed:
  build file '/home/max/IdeaProjects/Restaurant Rating App/build.gradle': 20: Unexpected input: ':' @ line 20, column 13.
     import group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: '2021.0.0', ext: 'pom'

自动生成的代码有什么问题?

谢谢!

4

1 回答 1

1

您的问题中的 与start.spring.iobuild.gradle的预期输出相匹配,但这两行除外:

// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies
import group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: '2021.0.0', ext: 'pom'

这不是有效的 Gradle 语法。只需删除它们即可解决手头的问题。

于 2022-02-14T19:39:35.590 回答