IntelliJ IDEA 2018.3 Help

Getting Started with Groovy

IntelliJ IDEA lets you create and run Groovy applications.

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

Create Groovy project

  1. Open Project Wizard, in the left-hand pane select Groovy.

  2. In the right-hand pane, specify the following settings:
    • Project SDK - specify your project SDK.

    • Groovy library - specify your Groovy SDK or click Create to choose one from the list that opens.

    • Additional libraries and frameworks - specify additional libraries and frameworks that Groovy supports.

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

      groovy create project

  3. Click Next.

  4. Specify your project information and click Finish.

    groovy project info

Add Groovy support to the existing project

  1. In the existing project, open the Project Structure dialog Ctrl+Shift+Alt+S.

  2. From the list on the left, select Modules.

  3. From the options on the right, select the Dependencies tab.

  4. Click the Add (icons general add) icon and select Library.

  5. In the dialog that opens, click New Library and from the drop-down list, select the library type.

  6. Download your library and it will appear in the list of module dependencies.

Alternatively, you can add a new Groovy module to your project (right-click your project in the Project tool window and select New | Module). On the page that opens, from the left-hand side, select Groovy and follow the steps suggested in the wizard.
IntelliJ IDEA will add a simple module with the attached Groovy library.

Create Groovy class

  1. Press Ctrl+N or in the Project tool window right-click on the directory and select New | Groovy Class.

  2. In the New Groovy Class dialog, in the Name field, specify a name of the class.

  3. In the Kind field, choose between class, interface, trait, enum or annotation.

    groovy new class

  4. Enter your code.

    groovy sample code

Create Groovy script

  1. Press Ctrl+N or in the Project tool window right-click on the directory and select New | Groovy Script.

    groovy new script

  2. In the dialog that opens, in the Name field, enter the name of your Groovy script. In the Kind field, choose between Groovy script and GroovyDSL script.

    groovy new script dialog

  3. IntelliJ IDEA creates a file with the specified name and groovy extension, and adds a node to the module tree view.

Run Groovy application

  1. Create a Run configuration using Run | Edit Configurations or run the active script automatically by pressing Ctrl+Shift+F10.

    groovy script running

  2. View the result in the Run tool window.

Last modified: 1 February 2019

See Also