So this is meant to be feedback to Jetbrains.
I changed the Kotlin version from 1.3.x to 1.4.0 in build.gradle.kts expecting it was all I had to do (let’s mention here that I had upgraded the IDE, and installed Plugins to the last version to expect this, also I use nothing marked as deprecated/ experimental in this project but that’s not the topic now). But than my build.gradle.kts become all red starting with my first “implementation”. A Mouse-over couldn’t give me useful information but in the top was a text telling me that the build failed (if I remember correctly). A Mouse-over on that told me to run Gradle.tasks, so after searching for it and finding it in the help folder of Gradle it told me that I was running Gradle 5.2.x and atleast 5.2.y is required for Kotlin 1.4. Finally I knew atleast what the problem is. Having no clue why my project is running on an outdated Gradle version despite me having a Gradle plugin installed that didn’t told me that I’m using an outdated Gradle version all the time despite me installing every update I get prompted with.
Than after investing time into figuring out how to upgrade Gradle (the Gradle plugin was up to date I rechecked it) I found in the settings of Intelij the option “use Gradle from” set to gradle-wrapper.properties file. Finally I knew the file I had to look into even thought I found it by luck in the settings. Finding that file wasn’t that hard after knowing it’s name but still I had to search for it because I don’t know much about Gradle and all its files and directories. Finally opening the file I could see “gradle-5.2.x-bin.zip” at the end of a line. I finally found it but still didn’t know what the newest Gradle version is. So a Websearch and I knew that 6.6.1 is the last one. I changed it and finally everything worked (which took its time but I understand that it had to download a new Gradle version first).
I hope by the length of my text you can see how much more time it took me to switch to 1.4 than I expected it to take. It took so much time that I thought it’s worth me typing this here so that in future this could be handled better. Also maybe someone else will have the same problem and this will help him saving him time. As said this is not a rant but a feedback to enable Jetbrains to make upgrading Kotlin less painful in the future.
So this is meant to be feedback to Jetbrains.
I feel your pain. It’s always annoying when upgrading software causes issues, but maybe some context will help you at least understand why this is the issue here.
I think we can all agree that it is fine for kotlin to change the required version of gradle to a newer version from time to time. The question is why does it not update gradle automatically with the rest of kotlin? Well gradle wrappers are used to ensure that you always build with the same version of gradle, regardles of what is installed on your machine. This is important (especially for teams) because it ensures that all builds are consistent everywhere. Your gradle plugin version doesn’t matter here.
As you figured out you need to upgrade the version specified in the gradle wrapper. You can either edit some settings file or you could run the
gradlew wrapper --gradle-version x.y.z command. You can also use
gradle ... instead. The
gradlew version calls gradle through the existing wrapper while the
gradle version tries to find gradle on your path. Also you should always use
gradlew when possible for the reasons I named above.
What could the kotlin team do to improve this in the future?
I don’t think automatically upgrading gradle is a good idea. That might lead to other issues, especially in teams that want to have a stricter controll over their build system. That said, maybe the kotlin gradle plugin could fail a bit more gracefully, eg. log error message to console and Idk display popup in IDE that asks the user to upgrade gradle.
Right, communicating what the error was in a better way would help a lot. I first spent time thinking about an chicken egg problem (the Gradle file was written in Kotlin, Kotlin was the part Gradle is going to upgrade). Also maybe a menu point that let’s you change the version number of the wrapper without the need to manually open the file (and by doing so it could warn you with a prompt that changing this could break your code if you have the luxus to work with team members). Also maybe I missed it but the announcement of Kotlin 1.4 could also state that a new Gradle version is needed and point to an explanation how to change it and the warning that in teams this could brake the code (the problem with this is that if you skip 1.4 you won’t find the notice the day you change to 1.5).
Try clearing Gradle caches
Why? As I said I wrote this after I solved the problem. And if my understanding of the problem is correct your suggestion wouldn’t help me before I solved it, since I needed to update Gradle and clearing the cache shouldn’t do that for me.
I think someone might not have read through your entire post. Clearning caches is a great way to fix some strange gradle errors that are caused by some inconsistent state. But as you said, it wouldn’t help in your situation.
@Wasabi375’s answer is spot on.
I just wanted to add that the Gradle wrapper is the reason Gradle projects are only two steps from development:
./gradlew build(or for windows,
No need to install Gradle, or anything else (except the JVM you probably already have)!
I’ve even uninstalled Gradle to avoid accidentally using it outside of the wrapper–which was an odd case of looking for scripts using it directly to remove them. But even after I was done I don’t think I bothered re-installing. If it’s bundled in the project via the wrapper, then the wrapper is intended to be used.