Gradle is a popular open source build automation system. You can take full advantage of Gradle in Liferay Dev Studio through Buildship, a collection of Eclipse plugins that provide support for building software using Gradle with Liferay Dev Studio. Buildship is bundled with Liferay Dev Studio versions 3.0 and higher.
This reference article highlights some useful tips for leveraging Gradle in Dev Studio.
Note that creating Liferay Gradle projects and deploying Gradle projects with Dev Studio are covered in their respective articles.
The first thing you’ll learn about in this tutorial is creating pure Gradle projects in Dev Studio.
Creating Pure Gradle Projects
Most of Dev Studio’s wizards rely on your usage of Liferay Workspace. This is for good reason; it’s the recommended developer environment for Liferay projects. You can, however, create pure Gradle projects and manually configure them to be deployable to Liferay DXP.
You can create a pure Gradle project by using the Gradle Project wizard.
-
Navigate to File → New → Project….
-
Select Gradle → Gradle Project. Then click Next → Next.
-
Enter a valid project name. You can also specify your project location and working sets.
-
Optionally, you can navigate to the next page and specify your Gradle distribution and other advanced options. Once you’re finished, select Finish.
Excellent! You’ve created a pure Gradle project using Dev Studio.
Importing Pure Gradle Projects
You can also import existing pure Gradle projects in Dev Studio.
-
Go to File → Import….
-
Select Gradle → Existing Gradle Project → Next → Next.
-
Click the Browse… button to choose a Gradle project.
-
Optionally, you can navigate to the next page and specify your Gradle distribution and other advanced options. Once you’re finished, click Next again to review the import configuration. Select Finish once you’ve confirmed your Gradle project import.
Next you’ll learn about Gradle tasks and executions, and learn how to run and display them in Dev Studio.
Gradle Tasks and Executions
Dev Studio provides two views to enhance your development experience using Gradle: Gradle Tasks and Gradle Executions. You can open these views by following the instructions below.
-
Go to Window → Show View → Other….
-
Navigate to the Gradle folder and open Gradle Tasks and Gradle Executions.
Gradle tasks and executions views open automatically once you create or import a Gradle project.
The Gradle Tasks view lets you display the Gradle tasks available for you to use in your Gradle project. Users can execute a task listed under the Gradle project by double-clicking it.
Once you’ve executed a Gradle task, you can open the Gradle Executions view to inspect its output.
Keep in mind that if you change the Gradle build scripts inside your Gradle
projects (e.g., build.gradle
or settings.gradle
), you must refresh the
project so Dev Studio can account for the change and display it properly in
your views. To refresh a Gradle project, right-click on the project and select
Gradle → Refresh Gradle Project.
If you prefer Eclipse refresh your Gradle projects automatically, navigate to Window → Preferences → Gradle and enable the Automatic Project Synchronization checkbox. If you’d like to enable Gradle’s automatic synchronization for just one Gradle project, you can right-click a Gradle project and select Properties → Gradle and enable auto sync that way.
Excellent! You’re now equipped with the knowledge to add, import, and build your Gradle projects in Liferay Dev Studio!