IntelliJ IDEA 2021.3 Help

Run/Debug Configuration: Gradle

You can run Gradle tasks using run configuration. The default options listed in such configuration are enough to run your task. If you want, you can also create an advanced configuration using additional options or adding more tasks and arguments.

Create a run/debug Gradle configuration

  1. From the main menu, select Add Configuration. Alternatively, right-click any task in the Gradle tool window and select Modify Run Configuration.

    Gradle configuration settings
  2. Specify a name of your configuration in the Name field to quickly identify it when editing or running the configuration, for example, from the Run popup Alt+Shift+F10 or the Gradle tool window.

  3. Specify where you want your configuration to run on. The default Local Machine option will run your configuration locally on your computer.

    You can change the location of your run execution. For example, use SSH or Docker to run your target.

    You can also run your target on WSL. If you need to configure a new target or change the existing configuration, click Manage targets and in the Run Targets dialog, add your changes. For more information, refer to Run targets.

  4. If you need, specify Store as project file that saves the file with the run configuration settings so you can share it with other team members. The default location is .idea/runConfigurations. However, if you do not want to share the .idea directory, you can save the configuration to any other directory within the project.

    To change the location, select this option and click the Manage File Location icon and in the dialog that opens, add the new location.

  5. If you don't need to specify anything in the Run field, the default tasks such as help and tasks specified in the Before build section. section will be executed. Alternatively, if you are creating a run configuration from the Gradle tool window, the task you have selected will be displayed in this field. However, you can specify additional external tasks and arguments for your run configuration. Use spaces to separate one task from another. If you want to see the available list of Gradle tasks and arguments, click the Insert Tasks and Arguments icon in the field.

  6. Specify the location of your Gradle project.

    You can either enter it manually or click the Browse button and point to the desired location in the dialog that opens. However, if you are creating a run configuration from the Gradle tool window, IntelliJ IDEA will display the name of your project automatically.

    You can also click Gradle registered projects the Modules node icon to select an available Gradle module from the list of registered Gradle modules in your existing IntelliJ IDEA project.

    If you need, you can specify a path to the build script file instead of the project path. This might be helpful if you have a custom build script to which you want to refer.

  7. If you need, specify the environment variables that you want to use in you project.

  8. The following default options are enabled, but you can click Modify options to add new options or remove some of the default ones in Add Run Options:

    • Open run/debug tool window when started - automatically opens the Run/Debug tool window when the configuration is executed and several debugger options

    • Debug forked tasks in the same session - makes the debug process to run under one tab. Remove (Android studio icons common close) this option if you want to see each debugging process in a separate tab.

    • Enable Gradle script debugging - enables breakpoints in the Gradle scripts.

      If the Let me choose per test option is selected and you decide to debug your test (select Debug 'test name' from the context menu in the gutter), IntelliJ IDEA clears the this option automatically to speed up the debugging process for your test.

      Option Debug forked tasks in the same session disabled

Modify run options

Click Modify options to add more run options or remove some of the default ones described above.

Gradle configuration settings

Operating System

Item

Description

Allow multiple instances

Select this option to allow running multiple instances of this run configuration in parallel. By default, it is disabled, and when you start this configuration while another instance is still running, IntelliJ IDEA suggests stopping the running instance and starting another one. This is helpful when a run configuration consumes a lot of resources and there is no good reason to run multiple instances.

Java

Item

Description

Add VM options

Use this field to specify VM options for your Gradle project.

If you need more room to type, click Icons general expand component next to the field to access the VM options dialog where the text entry area is larger.

When specifying JVM options, follow these rules:

  • Use spaces to separate individual options, for example, -client -ea -Xmx1024m.

  • If an option includes spaces, enclose the spaces or the argument that contains spaces in double quotes, for example, some" "arg or "some arg".

  • If an option includes double quotes (as part of the argument), escape the double quotes using backslashes, for example, -Dmy.prop=\"quoted_value\".

  • You can pass environment variable values to custom Java properties. For example, if you define a variable MY_ENV_VAR, you can pass it to the foo property as follows:

    -Dfoo=${MY_ENV_VAR}

Logs

You can select which log files that are generated while running or debugging should be displayed in the console, that is, on the dedicated tabs of the Run or Debug tool window. You can also select an an option that saves the console output to a file or show the console output when a message is printed to stdout or stderr.

Code Coverage

You can select options related to running your configuration with code coverage.

Before launch

You can select additional options to add before the run configuration is executed. For example, you can add a Gradle task that you want to execute before you run your configuration.

Click Add before launch task and in the list that opens, select Gradle task, and in the dialog that opens configure your task.

Gradle debug

Item

Description

Debug all tasks on the execution graph

When you select this option, every task in the execution graph will be debugged. For example, all the dependent tasks of the task you are trying to debug.

Last modified: 01 August 2022