Using Gradle in Liferay Developer Studio

Gradle is a popular open source build automation system. You can take full advantage of Gradle in Liferay Developer Studio by utilizing Buildship, which is a collection of Eclipse plugin-ins that provide support for building software using Gradle with Liferay Developer Studio. Buildship is bundled with Liferay Developer Studio versions 3.0 and higher.

Figure 1: Navigate to Help → Installation Details to view plugins included in Liferay Developer Studio.

Figure 1: Navigate to *Help* → *Installation Details* to view plugins included in Liferay Developer Studio.

The first thing you’ll learn about in this tutorial is creating Gradle projects in Developer Studio.

Creating and Importing Gradle Projects

You can create a Gradle project by using the Gradle Project wizard.

  1. Navigate to FileNewProject… and select GradleGradle Project. Finally, click NextNext.

  2. Enter a valid project name. You can also specify your project location and working sets.

  3. Optionally, you can navigate to the next page and specify your Gradle distribution and other advanced options. Once you’re finished, select Finish.

Figure 2: You can specify your Gradle distribution and advanced options such as home directories, JVM options, and program arguments.

Figure 2: You can specify your Gradle distribution and advanced options such as home directories, JVM options, and program arguments.

You can also import existing Gradle projects in Liferay Developer Studio.

  1. Go to FileImport…GradleGradle ProjectNextNext.

    Figure 3: You can specify what Gradle project to import from the Import Gradle Project wizard.

    Figure 3: You can specify what Gradle project to import from the *Import Gradle Project* wizard.

  2. Click the Browse… button to choose a Gradle project.

  3. 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.

    Figure 4: You can preview your Gradle projects import information.

    Figure 4: You can preview your Gradle project's import information.

Next you’ll learn about Gradle tasks and executions, and learn how to run and display them in Liferay Developer Studio.

Gradle Tasks and Executions

Liferay Developer Studio provides two views to enhance your developing experience using Gradle: Gradle Tasks and Gradle Executions. You can open these views by following the instructions below.

  1. Go to WindowShow ViewOther….

  2. 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 allows you to 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.

Figure 5: Navigate into your preferred Gradle project to view its available Gradle tasks.

Figure 5: Navigate into your preferred Gradle project to view its available Gradle tasks.

Once you’ve executed a Gradle task, you can open the Gradle Executions view to inspect its output.

Figure 6: The Gradle Executions view helps you visualize the Gradle build process.

Figure 6: The Gradle Executions view helps you visualize the Gradle build process.

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 Liferay Developer 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 GradleRefresh Gradle Project.

Figure 7: Make sure to always refresh your Gradle project in Liferay Developer Studio after build script edits.

Figure 7: Make sure to always refresh your Gradle project in Liferay Developer Studio after build script edits.

If you prefer Eclipse refresh your Gradle projects automatically, navigate to WindowPreferencesGradle 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 PropertiesGradle and enable auto sync that way. This feature is available in Buildship version 2.2+, so make sure you have the required version.

Excellent! You’re now equipped with the knowledge to add, import, and build your Gradle projects in Liferay Developer Studio!

« Enabling Code Assist Features in Your ProjectUsing Maven in Liferay Developer Studio »
Was this article helpful?
1 out of 1 found this helpful