javagradleintellij-ideaspring-initializr

build.gradle created by Spring Initializr error message on "import" function


I am new to Gradle and I followed the instructions of a tutorial, just that instead of Maven I chose Gradle in Spring.Initializr.

It produced following code for the 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()
}

I receive the error message

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'

What is wrong with the autogenerated code?


Solution

  • The build.gradle in your question matches the expected output from start.spring.io except these two lines:

    // 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'
    

    This is not valid Gradle syntax. Simply removing them will fix the issue at hand.