Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Note
iconfalse

See also the tutorial Getting Started with Grails to learn how to create web applications with Grails.

...

Wiki Markup
{redirect:https://www.jetbrains.com/idea/help/groovy.html

...

|delay

...

=0}

1. Enable the plugin

Before you create your first Groovy application make sure Groovy plugin is enabled in

span
classshortcut
Settings
Plugins
span
classshortcut
Wiki Markup
{span:class=shortcut}Settings{span}
Wiki Markup
{span:class=shortcut}Plugins{span}
.

2. Create a new project

Open

Project Wizard
span
classshortcut
Wiki Markup
{span:class=shortcut}Project Wizard{span}
and select Groovy template. Since Groovy requires Java you have to specify the Project SDK
span
classshortcut
Wiki Markup
{span:class=shortcut}Project SDK{span}
.

If you create a Groovy project for the first time IntelliJ IDEA will offer you to create Groovy SDK library. Press

Create
span
classshortcut
Wiki Markup
{span:class=shortcut}Create{span}
button and choose directory with a Groovy SDK.

...

The easiest way to create Groovy class or script is to use

span
classshortcut
Ctrl
+
span
classshortcut
N
shortcut from
span
classshortcut
Project View
or Navigation Bar
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl{span}
+
Wiki Markup
{span:class=shortcut}N{span}
shortcut from
Wiki Markup
{span:class=shortcut}Project View{span}
or
Wiki Markup
{span:class=shortcut}Navigation Bar{span}
.

Choose between class, interface, enum and annotation with

span
classshortcut
Up
and Down
span
classshortcut
Wiki Markup
{span:class=shortcut}Up{span}
and
Wiki Markup
{span:class=shortcut}Down{span}
arrows.

Let's create a class with a method returning

span
classid
Wiki Markup
{span:class=id}"Hello, world!"{span}
string.

4. Create a new script

Now we can create a script file via

span
classshortcut
Ctrl
+ N
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl{span}
+
Wiki Markup
{span:class=shortcut}N{span}
shortcut.

Choose between script and GroovyDSL script with

span
classshortcut
Up
and Down
span
classshortcut
Wiki Markup
{span:class=shortcut}Up{span}
and
Wiki Markup
{span:class=shortcut}Down{span}
arrows.

Now we can create an instance of our class and invoke

hello
span
classid
Wiki Markup
{span:class=id}hello{span}
method.

5. Run the project

In order to run the application you can manually create a Run configuration via

span
classshortcut
Run
Edit configurations
span
classshortcut
Wiki Markup
{span:class=shortcut}Run{span}
Wiki Markup
{span:class=shortcut}Edit configurations{span}
or run the active script automatically by pressing
span
classshortcut
Ctrl
+
span
classshortcut
Shift
+ F10
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl{span}
+
Wiki Markup
{span:class=shortcut}Shift{span}
+
Wiki Markup
{span:class=shortcut}F10{span}
shortcut.

Note
iconfalse

See also the tutorial Getting Started with Grails to learn how to create web applications with Grails.