We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
If you have a Gradle project running on an older version (in my case, it was using Gradle 6.8) and you want to update it to Gradle 7.0, it will just take a couple of steps.
First, we will check if there are any warnings we need to fix before we can update. This can be done by executing:
$ ./gradlew wrapper --warning-mode all
> Configure project :
The JavaApplication.setMainClassName(String) method has been deprecated. This is scheduled to be removed in Gradle 8.0. Use #getMainClass().set(...) instead. See https://docs.gradle.org/6.8/dsl/org.gradle.api.plugins.JavaApplication.html#org.gradle.api.plugins.JavaApplication:mainClass for more details.
at Build_gradle$5.execute(build.gradle.kts:40)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
BUILD SUCCESSFUL in 935ms
1 actionable task: 1 executed
In this case, the way you specify the main class for your application needs to be changed. So, instead of setting it like this in your build.gradle.kts
file:
application {
mainClassName = "MainKt"
}
It needs to become:
application {
mainClass.set("MainKt")
}
Now, all that is left is to perform the actual Gradle update. This is done by executing:
$ ./gradlew wrapper --gradle-version 7.0
BUILD SUCCESSFUL in 6s
1 actionable task: 1 executed
We can check that everything went fine by executing:
$ ./gradlew wrapper --version
------------------------------------------------------------
Gradle 7.0
------------------------------------------------------------
Build time: 2021-04-09 22:27:31 UTC
Revision: d5661e3f0e07a8caff705f1badf79fb5df8022c4
Kotlin: 1.4.31
Groovy: 3.0.7
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.8 (JetBrains s.r.o 11.0.8+10-b944.6916264)
OS: Mac OS X 10.16 x86_64
PS: if you want to go very fancy for checking the deprecations, you can also do a build scan:
$ ./gradlew help --scan
This will create a nicely formatted online report of the deprecations found in your project (if there are any).
I've made a simple sample project showing this. You can find the relevant commit here.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.