springboot-how to solve Plugin [id: 'org.springframework.boot', version: '2.4.2.RELEASE', apply: false] was not found in any of the following sources

Problem

When we run a spring boot application with gradle, sometimes, this error would occur:

15:46:15: Executing task 'bootRun'...


FAILURE: Build failed with an exception.

* Where:
Build file '/Users/bswen/private/bw/bswen-github/bswen-springboot23/build.gradle' line: 22

* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.4.2.RELEASE', apply: false] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.4.2.RELEASE')
  Searched in the following repositories:
    Gradle Central Plugin Repository

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
15:46:18: Task execution finished 'bootRun'.

The core exception is:

Plugin [id: 'org.springframework.boot', version: '2.4.2.RELEASE', apply: false] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.4.2.RELEASE')
  Searched in the following repositories:
    Gradle Central Plugin Repository

But I am sure everything is correctly configured, and the dependencies should be ok.

Environment

  • SpringBoot 2.x
  • Gradle 6.x

The configurations

Let’s check the project’s build.gradle:

group 'com.bswen.app9'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.3.2.RELEASE")
    }
}

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

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

Solution

We should notice that the plugin org.springframework.boot’s version is 2.4.2.RELEASE, after check, we know that there is no version named 2.4.2.RELEASE, we should use 2.4.2 instead.

Change as follows:

Change from:

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

To:

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

Rebuild the project and run it:

image-20210220161353910

It works!

All the example code and config files can be found in this github project.