Search

Dark theme | Light theme

October 16, 2009

Simple Groovy Project in IntelliJ IDEA Community Edition

The Community Edition of JetBrain's IntelliJ IDEA promises to be a good IDE to create Groovy applications and scripts. Let's start with a simple Groovy project and create a very simple script to see how easy it is to get started. We start IntelliJ IDEA 9 Community Edition and create a new project (File | Project). IntelliJ shows a dialog where we select the first option: Create Project From Scratch and we click on the Next button.

In the next screen we type in a name for our project: helloworld. We must make sure we select Java Module. We can change the location of our project if we want, but we can also leave the default values. We select the Next button to go the next screen.

Now we can change the source directory, but for now we leave the value src as is. When we click on the Next button we get to the last screen.

In this final screen we can select Groovy. If we installed the Scala plugin we also get Scala as an option, but for this example we only have to select Groovy. As this is the first Groovy project we are creating we must define a Groovy directory.

We select the ... button in the Groovy Settings section. IntelliJ opens a dialog window to select the directory where we installed Groovy on our local computer. Once we have selected the directory we want we click on the OK button.

IntelliJ has all information to create a new project so we click the Finish button. During the creation process we get a dialog window with the question if we want our Groovy library to be only for our project or global, so it can be used in other projects. Let's select the option to create a global library, so we can use it again when we create a new Groovy project in the future.

We now have our newly created helloworld project. When we right-click on the src node we get a pop-up menu. Here we select New | Groovy Script to create a new script.

We have to set a name for our Groovy script in the following dialog window. Let's call our script HelloWorld and press the OK button.

Our project contains the file HelloWorld.groovy and it is opened in the editor. We can type our code and run it with Run | Run... (or press Alt+Shift+F10 in Windows). IntelliJ IDEA provides code completion for Groovy methods and variables, so with a few keystrokes we can write our Groovy scripts and classes.

IntelliJ IDEA 9 Community Edition is a good Groovy editor to create Groovy applications with code completion, compiler, debugger, syntax highlighting and smart code navigation and search.