Blogs
Liferay is rolling out support for Gradle 7. Read on to see how easy it is to upgrade your existing workspaces to use Gradle 7...
Introduction
So for some time now, Liferay builds have been stuck on Gradle 6. Which, you know, is 2 releases behind the currently available Gradle 8...
But, after a lot of work, Liferay is ready to release support for Gradle 7.
Gradle 7?
Yes, that's right, I wrote Gradle 7, not Gradle 8. Apparently the release of Gradle 8 occurred some time after the work to upgrade to Gradle 7 had already started, so Gradle 8 was not started (yet I hope).
Now, you may be asking, why does it take so long to update between different versions of Gradle?
It all comes down to the plugins. Liferay has a bunch of custom plugins to manage the Liferay source builds and the Liferay workspace builds... There is a separate plugin for themes, a separate plugin for docker, a separate plugin for wars, a separate plugin for modules, a separate plugin for tarballs, for Node builds, for Service Builder, for REST Builder, ..., and then there's the workspace plugin which is responsible for orchestrating all of these smaller plugins.
Add to that the complexity of building Liferay from source (I don't recommend it, I try to avoid it, and trust me the build itself is quite complicated)...
In order to support Gradle 7, both the workspace plugins and the building Liferay from source (based a lot on the plugins) needed to work correctly.
And now the hard work from the dev tools team has finally completed and Gradle 7 support is ready, so what do you need to do?
Updating Your Workspace for Gradle 7
It's actually pretty straight forward to upgrade to Gradle 7. We'll be able to do so with just editing two files...
Updating the Gradle Wrapper
This will actually be handled for us completely. Just use the following command:
./gradlew wrapper --gradle-version 7.3.3
The wrapper will take care of updating the wrapper, updating the wrapper properties, and preparing for your Gradle 7 journey.
Updating the Workspace Plugin Version
The next file we update is the settings.gradle file. We're going to update the workspace plugin version to 8.0.6 (you can check https://repository.liferay.com/nexus/content/repositories/liferay-public-releases/com/liferay/com.liferay.gradle.plugins.workspace/ for availability of later versions).
My file looks like the following:
buildscript { dependencies { classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd.gradle", version: "5.3.0" classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "8.0.6" } repositories { mavenLocal() maven { url "https://repository-cdn.liferay.com/nexus/content/groups/public" } } } apply plugin: "com.liferay.workspace"
Next, we need to update our build.gradle files...
Updating build.gradle Files
So we do have to change our build.gradle files, making the following replacements:
-
compile
directive needs to switch toimplementation
-
testCompile
directive needs to switch totestImplementation
You can find other replacements noted here: https://docs.gradle.org/current/userguide/upgrading_version_6.html#sec:configuration_removal
Note that compileOnly
and
compileInclude
will remain unchanged.
compileOnly
is a directive for the java plugin, and it
hasn't been changed for Gradle 7. compileInclude
is a
Liferay-specific directive, and it too has not been changed for
Gradle 7.
Really, That's It?
Yes, really, it's just those three little steps.
Updating the wrapper will have the gradlew script download Gradle 7.3.3 and use it for the builds.
Updating the settings.gradle
file to use the new
version of the workspace plugin will have it, in turn, pulling in the
correct versions of all the minor plugins that are Gradle 7-compatible.
Changing the two legacy directives will allow the build.gradle files to work with Gradle 7.
Now, when you do your builds, you'll be using Gradle 7 and not Gradle 6.
Conclusion
So here we've updated your builds to go from Gradle 6 to Gradle 7.
Yes, I know it's not Gradle 8, but it is still forward progress.
I do have a ticket open, https://liferay.atlassian.net/browse/LPS-194200 for adding Gradle 8 support, so you can keep an eye on that one to see if it gets any traction...
Update 09/20/2023 - Gradle 7.6.2 is Working
Yes, that's right. If you use workspace plugin version 8.0.8+, you can use the very latest Gradle 7 version, currently 7.6.2.