java-How to solve Spring Boot plugin requires Gradle 5 or Gradle 6 Exception when building springboot applications with gradle

Problem

When we build spring boot applications with gradle, sometimes we get this error :

Build file '/Users/bswen/private/bw/bswen-github/bswen-project/spring-boot-23/build.gradle' line: 2

An exception occurred applying plugin request [id: 'org.springframework.boot', version: '2.3.2.RELEASE']
> Failed to apply plugin [id 'org.springframework.boot']
   > Spring Boot plugin requires Gradle 5 (5.6.x only) or Gradle 6 (6.3 or later). The current version is Gradle 5.2.1

Environments

The environments are as follows:

  • java version: jdk 1.8
  • spring boot version: 2.3.2.RELEASE

The build.gradle

The build.gradle of this spring boot application is as follows:

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

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

sourceCompatibility = 1.8

repositories {
    mavenLocal()
    maven { url 'https://maven.aliyun.com/repository/google/' }
    maven { url 'https://maven.aliyun.com/repository/public/' }
    maven { url 'https://maven.aliyun.com/repository/spring/' }
    maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
    maven { url 'https://maven.aliyun.com/repository/spring-plugin/' }

    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

How to solve the problem

This error is caused by the incorrect gradle version in the ./gradle/wrapper/gradle-wrapper.properties, please do as follows:

open the ./gradle/wrapper/gradle-wrapper.properties ,find the line:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.0.1-bin.zip 

change the version 5.0.1 to 5.6.1 or higher version of gradle.

After this change, the whole ./gradle/wrapper/gradle-wrapper.properties file is as follows:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

The code base of this example is uploaded to github.com, you can click this web url to download the code.

References

You can view some references as follows: