Getting Started with Grails
IntelliJ IDEA supports Grails version 3.0 and later.
For working with Grails older versions, refer to the Getting Started with Grails 1/2 section.
Create Grails project
Before you start creating your project with Grails framework, make sure you have the latest Grails SDK version downloaded on your machine.
Open Project Wizard, in the left-hand pane select Grails .
- 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 version 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. In our case, it is
Options - use this field for additional options. For example, you can specify a profile such as
On the next page of the wizard, specify the project's information such as name and location, and click Finish.
IntelliJ IDEA creates a Grails application with appropriate directories and artifacts.
Open an existing Grails project
Starting with the Grails 3.0 version, Grails projects use Gradle build system. You can use Gradle to open your project. IntelliJ IDEA imports the project and creates the specific folder structure and all the necessary artifacts.
From the main menu, select build.gradle file or a directory containing the build.gradle file.and the
If you need more information on working with Gradle in IntelliJ IDEA, refer to the Gradle section.
Explore Grails application
There are some notable differences in the Grails project structure as appose to projects with older Grails versions:
build.gradle - the Grails versions 3.0 and later use Gradle for building.
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 (
Application.groovy) file the lets you run and debug your application with default settings.
- The Grails view is supported.
All the Project view settings are available for the Grails view as well.
Grails actions are available in the Project view. All artifact icons are changed to Grails icons ( ).
For more information on the differences, refer to the Grails documentation.
Run Grails application
When you create a Grails application, IntelliJ IDEA creates a run configuration along with your project.
On the main toolbar, click to execute the application. If you want to edit the created run configuration, from the main menu select.
You can also run your application from the editor:
In the Project tool window, click the init folder.
From the list, select Application.groovy to open the file in the editor.
In the editor, in the left gutter, click and in the window that opens click Run 'Application main()'.
Your application starts in the default browser, with the following URL in the address bar:http://localhost:8080/
Debug Grails application
IntelliJ IDEA lets you debug your Grails application using the main application.
In the Project tool window, open init directory and right-click the Application.groovy file.
From the list select Debug Grails:'name'
You can also use the editor to start the debugging process. Open the Application.groovy file in the editor and click in the left gutter to start a debugging process with the Debug 'name' option.
Debug Grails application with Gradle tasks
IntelliJ IDEA lets you also debug your Grails application using Gradle tasks.
Open the Gradle tool window.
From the list of tasks, click application and in the list that opens, right-click run.
From the list that opens, select Debug Grails:'name'.
Grails coding assistance
You can use the following coding assistance in your Grails project:
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.
IntelliJ IDEA provides navigation between the injected dependencies.
IntelliJ IDEA also provides navigation between the methods of the controller and gsp files.
IntelliJ IDEA lets you open and check the hierarchy of the domain classes. Press Ctrl+H in the editor to open Hierarchy tool window.
IntelliJ IDEA also lets you check the domain classes dependencies.