IntelliJ IDEA 2021.3 Help

Go run/debug configurations

Create a run/debug configuration

  1. Open the Run/Debug Configuration dialog in one of the following ways:

    • Select Run | Edit Configurations from the main menu.

    • With the Navigation bar visible (View | Appearance | Navigation Bar), choose Edit Configurations from the run/debug configuration selector.

    • Press Alt+Shift+F10 and then press 0.

  2. In the Run/Debug Configuration dialog, click the Add New Configuration icon (the Add New Configuration icon) on the toolbar or press Alt+Insert. The list shows the default run/debug configurations. Select the desired configuration type (for example, Go build).

    The fields that appear in the right-hand pane display the default settings for the selected configuration type.

    • Run kind: a building scope for your application. File and Package scopes work similarly in tests and compilation/running configurations (in terms of the scope they cover).

      • Directory: build an application in the specified directory as a package, without processing any subdirectories.

        For test configurations, IntelliJ IDEA runs all the tests in the specified directory and all its subdirectories.

      • File: build an application from files specified in the Files field. To pass multiple file paths, use the vertical bar (|) as a delimiter. This configuration is automatically selected when you run your program from scratch files.

      • Package: build a single package with all its dependencies. Specify a full import path to the package that you want to build in the Package path field (for example, github.com/gorilla/mux). This configuration is automatically selected when you run the main function or a separate test by using the Run icon (the Run button) in the gutter.

    • Package path: a full import path of the package that you want to compile (for example, github.com/gorilla/mux). This field is available only when you select the Package run kind.

      You can press Ctrl+Space to see a list of available packages.

    • Output directory: a directory for the executable file.

    • Run after build: execute the application after the build.

    • Working directory: a directory that is used for the built application. If you have any code that creates relative files or directories, they will be relative to this directory.

    • Environment: environment variables for your application.

      To edit environment variables, click the Browse button at the end of the field. In the Environment Variables dialog, click the Add button and add the environment variables that you need.

      Add an environment variable
    • Go tool arguments: arguments for the go tool (for example, -o). Also, you can use macros in this field.

    • Use all custom build tags: all tags that are applied during the build. Tags are listed in settings Ctrl+Alt+S under Languages & Frameworks | Go | Build Tags & Vendoring.

    • Program arguments: arguments for the built application. Also, you can use macros in this field.

    • Run with sudo: grant sudo privileges for the application.

    • Module: name of the current module.

    • Before launch: add tasks that you want to launch before the launch of the selected run/debug configuration. To add a task click the Add button Alt+Insert and select the tool that you want to add.

    • Store as project file: Enable this option to save your configuration as a project file and share it with team members through VCS.

  3. Apply the changes and close the dialog.

Using macros

Macros are used to make a sequence of computing instructions available to the programmer as a single program statement. In IntelliJ IDEA, you can use macros in Go tool arguments and Program arguments fields.

  1. Navigate to Run | Edit configurations.

  2. Select or create a run/debug configuration in which you plan to use macros.

  3. In Go tool arguments and Program arguments fields, click the Insert Macros icon (the Insert Macros icon ).

  4. In the Macros window, select a macro from the Macros list (for example, ClipboardContent - The clipboard content). In the Macro preview pane, you can see the output of the macro if the output is available.

  5. Click Insert.

    See the following animation, that shows the usage of the ClipboardContent macro. You can copy the code snippet from GitHub. Before running the run/debug configuration, copy one positive number to the clipboard.

    Using the ClipboardContent macro
Last modified: 01 August 2022