CLion 2023.1 Help

Gradle

Gradle is a build automation system that provides plugins to build C/C++ libraries and applications. In CLion, you can work with Gradle projects that are based on cpp-application and cpp-library plugins (for more details on C/C++ Gradle plugins, see this blog post: Introducing the new C++ plugins).

Fully-functional Gradle support in CLion is under development. You can share your feedback and follow the updates in this ticket: CPP-1104

Open a Gradle project

  1. Select File | Open from the main menu and point CLion to the build.gradle file.

  2. In the dialog that opens, click Open as a Project.

  3. CLion will load the project, displaying the progress and status in the Build tool window:

    An opened Gradle project

Adjust the project settings

  1. Go to Settings | Build Tools | Gradle.

  2. If required, configure the project settings:

    Gradle project settings

    Refer to the dialog's reference page for details.

Configure auto-reload

By default, CLion doesn't reload your project automatically except for the cases of external changes like VCS update. You can change this behavior in the Build Tools settings.

  1. Go to Settings | Build, Execution, Deployment | Build Tools | Gradle.

  2. Select one of the auto-reload options:

    Auto-reload settings
    • Any changes - project reload will be triggered on any change in the build.gradle scripts.

    • External changes (default) - your project will be reloaded only upon external events like VCS update. In case of other changes, you need to reload your project manually. Use one of the following options:

      • Click the popup that appears in the editor:

        Editor popup for reloading the project
      • Click Reload Gradle Project in the Build tool window:

        Reload project from the Build tool window
      • Click Reload All Gradle Projects in the Gradle tool window:

        Reload project from the Gradle tool window

Run/Debug configurations for Gradle projects

CLion extracts run/debug configurations from the build.gradle file. You can change the extracted configurations and create new ones in the Run | Edit Run/Debug Configurations dialog.

There are two run/debug configurations available for Gradle projects, Gradle icons gradle Gradle and App run configurations application Gradle Native Application (the latter requires the Gradle Native plugin).

Set up a Gradle configuration

Gradle configuration settings

In the Gradle icons gradle Gradle configuration dialog, configure the following settings:

  • Run - specify the tasks you want to execute. Note that you can run several tasks in one Run/Debug configuration. For example, clean and build. You can also add Gradle command line parameters here, for example, --debug.

  • Gradle project - specify the location of your Gradle project. Click Cl gradle prjicon to select from the list of the registered Gradle projects.

    Set up a Gradle Native Application configuration

    In the App run configurations application Gradle Native Application configuration dialog:

    • In the Target field, select the desired target from the list:

      List of targets for Gradle Native Application
    • In the Executable field, select the proper executable for your configuration.

      Working with Gradle tasks

      CLion lets you run Gradle tasks using several different ways such as using a toolbar in the Gradle tool window, using a run configuration, and using a context menu.

      Run a Gradle task from the Gradle toolbar

      1. In the Gradle tool window (View | Tool Windows | Gradle), click Gradle icons gradle on the toolbar.

      2. In the Run Gradle Task dialog that opens, start entering the name of the task in the Command line field. CLion displays the list of Gradle tasks from which you can select the appropriate one:

        Run Gradle task
      3. CLion runs the selected task and displays the result in the Run tool window:

        Run Gradle task

        CLion also saves the task under the Run Configurations node in the Gradle window:

        Run Gradle task

      Use context menu to run a Gradle task

      • The first option is to select Run from the context menu of the desired task in the Gradle projects tool window.

      • If the task already has a corresponding Run/Debug configuration, you will see the Select option in the context menu. You can use this option to set the active configuration, and then run it.

        Run Gradle task
      • If there is no corresponding configuration for the task, the context menu will contain the Create option. Choose this option to open the Run/Debug Configuration dialog and create a configuration with the selected task.

      • All the available Run/Debug configurations are listed under the Run configurations node. Use the Run option from the context menu to run the tasks presented under this node:

        Run Gradle task

      Running Gradle Native applications

      In CLion, you can run and debug a Gradle Native application in the same way as a regular application.

      For example, you can use the App actions execute icon in the left gutter beside the code entry points. Click App actions execute and choose the desired action from the list. If there is no existing Gradle Native configuration for the target, a new configuration will be created before the launch.

      Run gutter

      Issues and limitations

      In the current initial phase of the Gradle support in CLion, there are several known problems and functionality restrictions:

      • CLion does not provide a project template for Gradle, so you can't create a new Gradle project via the New Project wizard.

      • Debugging Gradle tasks themselves is unavailable.

      Last modified: 11 January 2023