'cannot resolve org.springframework.cloud:spring-cloud-starter-config

I am using gradle to build and here is my build.gradle

Is there anything that I am missing in the gradle file

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/libs-milestone" }
    maven { url "https://repo.spring.io/libs-snapshot" }     
}

apply plugin: 'org.springframework.boot'
apply plugin: 'java'
apply plugin: 'javac2'
apply plugin: 'docker'

dependencies {
   compile project(':services')
   compile 'org.springframework.boot:spring-boot-starter-web'
   compile('org.springframework.cloud:spring-cloud-starter-config')
   compile('org.springframework.boot:spring-boot-starter-actuator')
   compile 'org.jetbrains:annotations:13.0'
   runtime 'org.aspectj:aspectjweaver'

   testCompile 'junit:junit'
   testCompile 'org.springframework.boot:spring-boot-starter-test'
   testRuntime "com.jayway.awaitility:awaitility:$awaitilityVersion"
   testRuntime 'com.jayway.jsonpath:json-path'
}

apply plugin: 'java'

springBoot {
executable = true
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Finchley.BUILD-SNAPSHOT"
}
}

docker {
baseImage "java:8"
}

task buildDocker(type: Docker, dependsOn: build) {
applicationName = "ldp-data-fetcher"
exposePort(8080)
addFile("${buildDir}/libs/app-0.1-SNAPSHOT.jar", "/opt/jmg/app-0.1-SNAPSHOT.jar")
}

sourceCompatibility = 1.8
targetCompatibility = 1.8


Solution 1:[1]

Try to use:

dependencies { 
  [...]
  compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-config', version: '2.0.1.RELEASE'
}

instead of:

compile('org.springframework.cloud:spring-cloud-starter-config')

Solution 2:[2]

The first answer is correct or you can explicitly define dependency management and versions as follows:

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

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

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

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-config-server'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

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

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

Solution 3:[3]

ext {
    set('springCloudVersion', "2021.x.x")
}

springCloudVersion not specified, adding this extension in root of file worked for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Ciamberlano
Solution 2 Dharman
Solution 3 Alexey Zatsepin