Creating Groovy Classes in Grails

I'm trying to do some Grails development using IDEA 13 EAP (133.609) on Windows 7.  I bumped into something that may be an IDEA issue, or simply my not understanding how to use it properly.

For those not familiar with Grails (a truly wonderful web application platform!), a Grails project has a very specific directory structure. Different Grails artifacts go into different directories, but general purpose code not one of the Grails artrifacts goes under either the /src/groovy or /src/java folder, depending on whether it's Groovy or Java source.

I wanted to create a general purpose Groovy class in the package com.example.  My natural inclination was to right click on the src/groovy folder in IDEA and choose New | Groovy Class. The only problem with that approach is, there is no such menu.  There is an option for a New | Groovy Script, but a Groovy Script isn't really the same thing as a Groovy class.

I then right clicked on the src/java menu, and what do you know!  There's a New | Groovy Class menu item available from a context menu on src/java.  Thinking maybe the menu is just misconfigured and a Groovy class would actually get created under the src/groovy folder, I chose that New | Groovy Class option and entered com.example.Sample. Indeed, a Groovy class was created in the correct package, but the package and Groovy class was created in the src/java folder.

I'm thinking the New | Groovy Class menu is just being associated with the wrong folder (src/java instead of src/groovy).  (Of course, the same misconfigured menu options are available from the main menu; i.e., with src/groovy selected there's no File | New | Groovy Class option, but with src/java selected there is.)

Since I'm not sure if Grails would have an issue with a Groovy class in the src/java folder, I manually moved the package and Groovy class to the src/groovy folder.  I can continue to do this to work around IDEA, but am left wondering,

Is this a bug or a feature, or am I just doing something wrong? :-)

Thanks for any help.

PS. While experimenting, I also noticed the New | Groovy  Class created a class properly, but the source generated for Interface,  Enum, and Annotation types all included the public visibility modifier which is assumed in Groovy.

1 comment
Comment actions Permalink

Sorry to answer this myself, but I found the cause of the menu issue.

The cause was that the /src/groovy folder was not marked as sources in the Module configuration. Apparently, this completely befuddled IDEA.  I'm not sure why src/groovy wasn't tagged as being a source folder.

To verify src/groovy would be created as a source folder, I created a new Grails project. I noticed that src/groovy was correctly tagged as being a source folder.

The project I was working on had recently had its Grails version upgraded and I upgraded to the latest EAP, but I don't really that those actions would cause the problem.

So the cause of the bad menu behavior is known and my question answered.  How src/groovy stopped being tagged as a source folder, I'm not sure, but I'm now wiser about what to look for if menus start disappearing.

(The other minor issue with the public visibility modifier being prepended for Groovy enum, interface and annotation types remains an issue for another day.)



Please sign in to leave a comment.