Search code examples
spring-bootgradlesdkman

Gradle wrapper is refusing to download and use version 6.7.1


I have Gradle 6.2.2 running on my system (Mac) and I need it to stay on 6.2.2 for a few critical projects that I run locally.

I just cloned another project, one maintained by other developers who are all using Gradle 6.7.1. It is a Spring Boot app. When I run any of its Gradle commands on the command-line I get:

> 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.2.2

So it looks like Spring Boot wants me to be on Gradle 6.3+.

My understanding of the Gradle Wrapper (please correct me if I'm wrong) is:

  1. you modify build.gradle with a wrapper directive that specifies which version of Gradle to use for the project
  2. you then run gradle wrapper on the command line and Gradle downloads & caches (somewhere) that version of Gradle for you
  3. now you can run your normal Gradle commands, but instead of gradle you use gradlew and that tells Gradle to use the version of Gradle specified in the wrapper directive

If any of that is incorrect or misleading, please begin by correcting me! Assuming its more or less correct...

I added the following directive in the project's build.gradle:

wrapper{
    gradleVersion = '6.7.1'
    distributionType = Wrapper.DistributionType.BIN
}

My hope here is that although I am using 6.2.2 locally on my system, this will tell Gradle to fetch and use Gradle v6.7.1 which we know is compatible with the rest of the project's build.

I then go to run gradle wrapper from the project root on my command-line:

$ gradle wrapper

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/myuser/workspace/the-new-project/build.gradle' line: 27

* What went wrong:
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 6.2.2

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

Any ideas as to what is going on here? How do I tell Gradle to download and use 6.7.1 but not touch my local version of 6.2.2?


Solution

  • Your understanding of the wrapper is correct (though for point 1, you can also specify the version and type on the command line, or rely on defaults by omitting them).

    If the project is not using the wrapper scripts already (there is no gradlew file in the project root), you need to manually download a compatible version of the distribution. Use this to generate the wrapper script and then from that point on, always use gradlew to build the project. You can delete the manually downloaded one afterwards if you like. This will not touch the older version you have installed yourself.

    If there actually is a wrapper script already, but it is configured for an incompatible version, then just manually change the version in the file gradle/wrapper/gradle-wrapper.properties. Be sure to run the wrapper task afterwards to get updates (if any) to the actual script.

    You should also consider using the wrapper for your own projects that require the older version 6.2.2. That way you don't have to worry about keeping locally installed distributions in the correct version and manually switching between them.