Search code examples
gradlegradlew

Getting a Gradle verion error even thoughn I appear to have the correct version installed


I get this error when I run a Gradle build:

$ ./gradlew clean build

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/paulcarron/Documents/Documents/Books/Learning Spring Boot 2/learning-spring-boot-2/build.gradle' line: 2

* What went wrong:
An exception occurred applying plugin request [id: 'org.springframework.boot', version: '2.3.1.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 6.0.1

* 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 759ms

I have Gradne 6.5 installed though:

$ gradle -v

------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------

Build time:   2020-06-02 20:46:21 UTC
Revision:     a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_121 (Oracle Corporation 25.121-b13)
OS:           Mac OS X 10.15.5 x86_64

What could the problem be here?


Solution

  • Just to nuance the correct answer in the comments.

    The program gradle, if you have it, invokes Gradle installed on your system. It's likely found from your PATH variable.

    The gradlew script (notice the 'w') is a wrapper script that is usually added to the Git repository. It invokes a declared version of Gradle, automatically downloading it beforehand if necessary. It uses its own installation folder (by default ~/.gradle/wrapper) and the version is declared in [repo]/gradle/wrapper/gradle-wrapper.properties).

    While you can change the version by hand, it is better to run ./gradle wrapper --gradle-version 6.5 --distribution-type all as this will also update the wrapper script itself if needed.