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.
Create Grails 3 project
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 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=webfor Grails 3.
On the next page of the wizard, specify the project's information and click Finish.
IntelliJ IDEA creates a Grails application with appropriate directories and artifacts.
Import Grails 3 project
Since Grails 3 is integrated with Gradle build system, you can import your project from the Gradle model.
- From the main menu, select build.gradle file or a directory containing the build.gradle file. IntelliJ IDEA will import a Gradle project even if the project was not opened or imported before. and the
- On the page that opens, specify the necessary options and click OK.
IntelliJ IDEA imports Grails project, creates the specific folder structure and all the necessary artifacts.
If you need more information on the Gradle project importing, refer to the Gradle import section.
Explore Grails application
There are some notable differences in Grails 3 project structure as appose to Grails 2:
build.gradle - the Grails version 3 uses Gradle for building. When you import Grails 3 project you should 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.
- The Grails view is supported for Grails 3.
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 Grails version 3 changes, see the Grails page.
Run Grails 3 application
When the Grails application is created it is ready to run.
Click the icon on the top right corner of your workspace.
If you want to run the application from the editor, perform the following steps:
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 icon and in the window that opens click Run 'Application main()'.
Your application starts in your default browser, with the following URL in the address bar:http://localhost:8080/
Debug Grails 3 application
IntelliJ IDEA lets you debug your Grails 3 application using Application.groovy.
In the Project tool window, open init directory and right-click the Application.groovy
From the list select Debug Grails:'name'
You can also use the editor to start the debugging process.
Debug Grails 3 application with Gradle tasks
IntelliJ IDEA lets you also debug your Grails 3 application using Gradle tasks.
Open 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 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.
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.