https://kotlinlang.org logo
Title
m

mudasar187

02/16/2023, 9:35 AM
Hi! Can anyone explain me why I should or why I should not use this properties in my
build.gradle.kts
withType<Wrapper>().configureEach {
        gradleVersion = "7.6"
    }
?
c

CLOVIS

02/16/2023, 9:36 AM
Does that even work? It's the wrapper which executes this, it can't change its own version
The proper way to select the version is in
gradle/wrapper/gradle-wrapper.properties
, which is read by the launcher script before the wrapper is started
m

mudasar187

02/16/2023, 9:38 AM
Agree, so I should remove the task and use the proper way to select version in gradle/wrapper/gradle-wrapper.properties?
c

CLOVIS

02/16/2023, 9:39 AM
That's what I would do. The only reason I see to use the task is if you want to upgrade the wrapper (set a newer version, run the
:wrapper
task and it will download it), but it's easier to run
./gradlew wrapper --gradle-version 8.0
m

mudasar187

02/16/2023, 9:40 AM
Agree 🙂 Thank you ! You confirmed my thoughts 🙂
c

Chrimaeon

02/16/2023, 9:52 AM
Of course you can set it in the wrapper task. When calling
gradle wrapper
it will update al necessary resources even the
gradlew
scripts if they where updated.
m

mudasar187

02/16/2023, 9:56 AM
I see. But it make it easier to remember just update the gradle via this command
./gradlew wrapper --gradle-version 8.0
🙂
c

Chrimaeon

02/16/2023, 9:58 AM
Sure, I just also have the Gradle version in the version catalog
c

CLOVIS

02/16/2023, 9:58 AM
That can't work.
Unless you also run
:wrapper
every time you touch it
(but someone will forget at some point)
just change the version in
gradle-wrapper.properties
or run the wrapper task with the new version number and you have nothing more to do
c

Chrimaeon

02/16/2023, 10:00 AM
We have a git clone script for doing it. So the wrapper jar does not need to be checked in to the git repo.
c

CLOVIS

02/16/2023, 10:01 AM
So every dev has to run
:wrapper
on their machine each time they change branches, or risk use the wrong Gradle version?
m

mudasar187

02/16/2023, 10:03 AM
I think there might be some point where a developer can 1. forget the command 2. Using wrong gradle version So i think using the way @CLOVIS mention is the better way to avoid some mistakes, errors etc..
v

Vampire

02/16/2023, 11:53 AM
Does that even work? It's the wrapper which executes this, it can't change its own version
Yes it works, it just does not do what you think it does. It configures the
wrapper
task which version to put into
gradle/wrapper/gradle-wrapper.properties
, it does not influence the current invocation of the wrapper. And because of that you also always have to call the
wrapper
task twice for a proper update, because the templates for the 4 wrapper files are taken from the currently running Gradle version. When you use the
wrapper
task to update the Gradle version, you effectively just change the version in the properties file (unless your wrapper files were from an even older Gradle version). Running the
wrapper
task again then update the wrapper files from the new version now already being used. Configuring the wrapper task in the build script has imho only one use-case. If you are disallowed to check in the wrapper files to VCS by some guidelines, then you can define there the version and wrapper checksum and so on, so that you can generate the wrapper files consistently after checkout of the project with some other projects wrapper or an installed Gradle version.