IntelliJ IDEA 2016.2 Help

Getting Started with Grails 3

IntelliJ IDEA supports Grails version 3.0 and later.

Before you start

Before you start creating your project with Grails framework, make sure that you have the latest Grails SDK version downloaded on your machine. You can download the latest SDK version from the Grails page. Also, make sure that you are working with IntelliJ IDEA ultimate edition, version 15 or higher if you want to work with the Grails 3.0 version. See the latest available version.

Creating Grails 3 Project

  1. Open Project Wizard, in the left-hand pane select Grails .
  2. In the right-hand part of the page, specify the following information:
    • Project JDK that you are going to use for your project.
    • Grails SDK Home - your local Grails 3 installation which is represented by a library.
    • Create create-app or create-plugin- select one of these options depending on what you want to create.
    • Options - use this field for additional options. For example, you can specify a profile such as --profile=web for Grails 3.0.

    Click Next.

    grails_new_project
  3. On the next page of the wizard, specify the project's information and click Finish.
    grails_new_project_info

IntelliJ IDEA creates the Grails application.

Exploring Grails Application

IntelliJ IDEA enables you to explore your Grails application. Note that the Grails View tool window is not supported for Grails 3. However, Grails actions are available in the Project View tool window. All artifact icons are changed to Grails icons. For Grails 1 and 2 versions the Grails View tool window is available.

grails3_project_view_with_grails_icons

Other notable differences from the previous Grails versions are as follows:

  • build.gradle - the Grails version 3.0 uses Gradle for building. When you import Grails 3 project you can import it through the Gradle model.
  • config directory - the content of the config directory enables you to use either a YAML file or Groovy file for your configuration. The logging configuration is also available.
  • init directory - this directory contains main application file the lets you run your application with default settings.
grails3_project_view

For more information on the Grails version 3 changes, please see the Grails page.

Running Grails 3 Application

When the Grails application is created it is ready to run.

Click the run icon on the top right corner of your workspace.

If you want to run the application from the editor, perform the following steps:

  1. In the Project tool window, click the init folder.
  2. From the drop-down list, select Application.groovy to open the file in the editor.
  3. In the editor, in the left gutter, click run_grails_from_left_gutter_icon icon and in the window that opens click Run 'Application main()'.
    run_app_options

Your application starts in your default browser, with the following URL in the address bar:

http://localhost:8080/

Debugging Grails 3 Application

IntelliJ IDEA lets you debug your Grails 3 application using Application.groovy.

  1. In the Project tool window, open init directory and right-click the Application.groovy
  2. From the drop-down list select Debug Grails:'name'
grails3_debug_app

You can also use the editor to start the debugging process.

grails3_debug_app_main

IntelliJ IDEA lets you also debug your Grails 3 application using Gradle tasks.

  1. Open Gradle tool window.
  2. From the list of tasks, click application and in the list that opens, right-click run.
  3. From the drop-down list that opens, select Debug Grails:'name'
grails3_debug_gradle

Grails 3 Coding Assistance

  • IntelliJ IDEA provides navigation between all related files such as domain classes, views, services and controllers. Press Ctrl+Alt+Home in the editor and choose your target.
    grails3_navigate_to_related
  • IntelliJ IDEA provides navigation between the injected dependencies.
    grails3_dependency_show
    grails3_show_related_dependency
  • IntelliJ IDEA also provides navigation between the methods of the controller and .gsp files.
    grails3_controller_gsp_show
    grails3_gsp_show
  • IntelliJ IDEA lets you open and check the hierarchy of the domain classes. Press Ctrl+H in the editor to open Hierarchy tool window.
    grails3_checking_hierarchy
  • IntelliJ IDEA also lets you check the domain classes dependencies.
    grails3_checking_domain_classes_dependencies

Grails 3 Gradle Support

Grails 3 uses Gradle build system. You can use Gradle for the following actions:

  • run Gradle tasks
  • rely on the coding assistance when you edit build files
  • import Grails 3 project from a Gradle model
  • automatically update project dependencies
grails3_gradle_build

See Also

Last modified: 5 September 2016