IntelliJ IDEA 2019.2 Help

Run, debug, and test Groovy

You can create, import, test, and run Groovy applications as you would any other projects.

Before you start working with Groovy, make sure that the Groovy plugin is enabled in IntelliJ IDEA.

Create a Groovy project

  1. In the Project Wizard, select Groovy.

  2. Specify the following settings:
    • Project SDK - specify your project SDK.

    • Groovy library - specify the Groovy SDK. IntelliJ IDEA expects the standard Groovy SDK layout which is provided with the official distributions available at http://groovy-lang.org/download.html. Download the SDK, unpack it into any directory and specify this directory as the library home.

    • Additional libraries and frameworks - if you need, specify additional libraries and frameworks that Groovy supports.

    • Java EE version - select the appropriate Java EE version.

      New Groovy Project

  3. Click Next.

  4. Specify your project information and click Finish.

To import a Groovy project, follow the steps from the Import a project section.

Check the version of Groovy in a project

You can check which version of Groovy SDK IntelliJ IDEA uses in a project.

  1. From the main menu select File | Project Structure Ctrl+Shift+Alt+S.

  2. In the Project Structure dialog, under Platform Settings, select Global Libraries.

    Project Structure dialog / Global Libraries
    If you need to check what Groovy SDK version is used in a module, select Modules, the module's name and click the Dependencies tab.
    Project Structure dialog / Module page

Change the existing Groovy SDK version in a project

  1. In the Project Structure Ctrl+Shift+Alt+S dialog, delete Ctrl+Y the existing Groovy SDK version from Global Libraries and from module dependencies (the Modules page).

  2. When the Groovy SDK is removed, IntelliJ IDEA displays a popup suggesting to add the Groovy SDK.

    Configure Groovy SDK popup
    Click the link and set up a new SDK.

  3. If, for some reason, IntelliJ IDEA does not display the popup, in the Project tool window, right-click the name of your project and in the context menu, select Add Framework Support.

  4. In the dialog that opens, from the list of technologies, select Groovy and add a new Groovy library.

    Add Framework Support dialog
    IntelliJ IDEA creates a global-level library.

Generate Groovy documentation

You can generate the API documentation for the Groovy and Java classes that compose the Groovy language.

  1. From the main menu, select Tools | Generated GroovyDoc.

  2. In the dialog that opens, specify the output directory for the documentation and other available options and click Start.

Run a Groovy application

After you entered code, you can run it through IntelliJ IDEA or use the interactive Groovy console for quick code evaluation.

  1. Open your application in the editor.

  2. Press Shift+F10 to execute the application. Alternatively, in the left gutter of the editor, click the icons toolwindows toolWindowRun svg icon and select Run 'name'.

    Run an application

  3. View the result in the Run tool window.

    Run tool window / run Groovy application

Debug a Groovy application

  1. Open your Groovy application in the editor.

  2. In the left gutter, set your breakpoints for the lines of code you want to debug. The debugger is aware of the Groovy syntax, and you can evaluate an expression on the breakpoint if you need.

    Evaluate expression
    For more information on breakpoints, please see the Breakpoints section.

  3. If you need, you can access the Run/Debug configurations dialog (Run | Edit Configurations) and adjust the settings, but usually the default settings are enough to successfully start and complete your debugging session.

  4. Press Shift+F9. Alternatively, on the main toolbar, click the icons actions startDebugger svg icon to start a debugging process.

  5. Evaluate the results in the Debug tool window.

    For information on how to use options in the Debug tool window, please see Debug tool window references.

When in the debug mode, you can evaluate any expression by using the Evaluate expression tool, which is accessed by pressing Alt+F8. This tool provides code completion in the same way as in the editor, so it's easy to enter any expression.

Sometimes, you may want to step into a particular method, but not the first one which will be invoked. In this case, use Smart step into by pressing Shift+F7 to choose a particular method.

Test a Groovy application

You can test Groovy applications using JUnit 4 and JUnit 5 testing frameworks.

  1. Open a class in the editor, for which you want to create a test and place the cursor within the line containing the class declaration.

  2. Press Ctrl+Shift+T and select Create New Test.

  3. In the dialog that opens, specify your test settings and click OK.

    create groovy test

  4. Open the test in the editor, add code and press Ctrl+Shift+F10 or right-click the test class and from the context menu select Run 'test name'.

  5. IntelliJ IDEA creates a run/debug configuration for the test automatically, but if you want to edit settings in your configuration, click Run | Edit Configurations on the main menu.

  6. In the Run/Debug Configurations dialog, on the right-hand side, specify settings for the test suite and click OK. The configuration has standard options and you can find further details in the Performing Tests section.

  7. On the main toolbar, click the icons toolwindows toolWindowRun svg icon to run the test.

  8. Evaluate the results in the Run tool window.

Last modified: 28 August 2019

See Also