0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
von spotz
  • 875
  • 7
  • 17

1 Answers1

1

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.

thokuest
  • 5,800
  • 24
  • 36
  • Hello thokuest, thanks for your answer. Could you tell me how I can load the `org.springframework.cloud:spring-cloud-dependencies` Plugin and the other dependencies for all subpackages to that module? Thanks – von spotz Feb 15 '22 at 17:03
  • In a `buildscript` closure? And then a `dependencies` attribute? https://docs.gradle.org/current/userguide/userguide_single.html#sec:build_script_external_dependencies How would that look exactly please and could one also share the other dependencies in the buildscript block with the child projects or should one put those into an `allprojects` method? Thanks – von spotz Feb 15 '22 at 17:10
  • I meant: should one put those into a `dependencies` attributes' block nested in an `allprojects` methods' block? – von spotz Feb 15 '22 at 17:16
  • @vonspotz May I ask you to open yet another question for this? To be honest, I don't really get your use case and a separate question may be best. Feel free to link it here for further reference. – thokuest Feb 15 '22 at 19:16
  • 1
    Hello thokuest, here is the link to the thread https://stackoverflow.com/questions/71138091/gradle-making-external-plugin-dependencies-for-the-build-script-and-normal-depe Thank you! – von spotz Feb 16 '22 at 07:58