That’s combining two different concepts. There’s really 2 ways to use a specific Gradle version:
- Download / install a specific version and run it (
gradle
).
- Use the Gradle wrapper, which downloads and run a specific version for the project regardless of what’s installed on the machine (
./gradlew
).
The wrapper is the preferred approach as it guarantees that the project builds with the version that it was authored for, not whatever someone happened to have installed at the time.
In order to use the wrapper in a project, you need to generate the wrapper files. This includes the gradlew
executable, a small JAR file, and the gradle-wrapper.properties
file.
If you just run the wrapper
task, it’s going to generate a wrapper with the current version of Gradle that is executing it (if using IDEA to create a project, that’s that default version that they happen to bundle).
Executing ./gradlew wrapper --gradle-version 7.0.2
executes the wrapper
task and configures it at command line. The wrapper { }
block in build.gradle
is exactly the same. It’s just setting your own default for that task so that it doesn’t have to be specified each time. Allowing configuration in the build.gradle
or via specific command line options is a pretty normal capability for a task.
The end result of running the wrapper
task will generate all the needed wrapper files, including the gradle-wrapper.properties
file. However, if you were in an empty folder, creating a new project yourself manually, you don’t have a working wrapper by just creating gradle-wrapper.properties
. The input of the wrapper
task is a version. The output includes gradle-wrapper.properties
.
Back to the IDEA settings. Use Gradle from
:
Specified location
- use a gradle
distribution you’ve already downloaded.
'gradle-wrapper.properties' file
- use the wrapper that’s already been generated.
'wrapper' task in Gradle build script
- use the wrapper, but run the wrapper
task first each time.
Running the wrapper
task every time the IDE configures the project is kind of a waste, so I’d always prefer using the wrapper that’s already generated. If you choose the wrapper
task option, but don’t configure it in the build.gradle
it’s going to get overwritten with IDEA’s bundled version.
Part of the issue ends up being that IDEs change how this is implemented with their different versions. You might be using Gradle 6.6
, but a version of IDEA that was released when 5.6.4
or when 7.0.2
was out. It’s also a trailing impact, so when releasing a version of Gradle, it’s not yet known how the IDEs will decide to update in response to that version. Gradle has documentation for the Gradle features, but it really needs to be the IDE that documents what their options (especially when they make up terms for the options) actually do.