Problem with creating domain classes in Grails plugin in IDEA 11.1.4

I haven't tried to create my own plugin before and have created Grails applications successfully but not recently so this may apply to any "New Grails Domain Class".

In summary while IDEA goes through the motions and does correctly create the class.goovy files they are not visible in the IDEA Grails View nor Project View.

I ran the New Project to create the plugin, using Grails 2.1.1, it seems to work correctly

I then created a domain class, this also appeared to work correctly and says it creates the .groovy file in the console log but nothing is displayed in the Grails View nor Project View (Left hand panes). After this first failure I checked in the actual files and there is a correct, blank domain class file there. I then created a second class and while it seemed to accept the entry it didn't show anything on the Console log after a few lines. I left it for a few minutes and repeated the same New Grails Domain Class, using the same name, and it worked, well it went through the motions and said it had created it but again nothing shows on the IDEA views. However as before the files are there. Interestingly the test files which are created during the create domain class process  are both visible in the Views

I closed IDEA and reloaded it but still no class showing.

I did note this problem with package names a few months ago (although no one responded)

Of course now Grails does insert a package statement at the start of the domain class.

The files were created in a directory ../domain/pckgname so I copied them up one level and removed the 'package' statment' still IDEA could not find them.

I then went back into IDEA and went through the  New Grails Domain Class and attempted to re-create one of the existing classes. Correctly it said it "...already exists, do you want to overwrite ?" I replied "No" and then suddenly all of the classes (the original pair and the pair I had copied) were shown.

I then created a completely new Grails Domain Class and it immediatley appeared as it should and presented itself in the right hand pane to be edited (the previous missing ones had not so done when they were created.
This is IDEA 11.1.4 (but I believe the same happens with 11.1.3 - I did a quick test when I first noticed the the problem) on Xubuntu 12.10, Grails 2.1.1.

I have to say that like the previous problem I noted it is rather irritating and has wasted a good few hours of my time.

I would welcome some comments

Comment actions Permalink

I've just done some further checking and certainly I can create a domain class in a standard Grails application as normal with 11.1.4

The purpose of the exercise is to create a plugin holding various domain classes and nothing else and then create a couple of applications that use the plugin - modularisation to avoid duplication etc.

ANd now having created the main app, my next step was to install the plugin that I had previously created and that worked. Then I discovered a minor problem when I wanted to create a controller in the main app. for a domain class from the plugin; this i can do in the grails console (generate-controller pluginpackagename.domainclass) but I couldn't find a way from the 'generate controller' option that is present in IDEA when editing the domain class itself. So having Exited IDEA and created a controller from the Grails console for one domain class I reloaded IDEA, only to find that it doesn't see that controller although the file is there in main app's ../controller/pluginpackagename/ directory as expected. However I did find that by using IDEA to run the grails command 'generate-controller...', i.e. exactly as I used in the Grails Console, it does create the controller for the plugin domain class in the main app's directories - which is good - but the two controllers are still not visibile in the IDEA Grails View nor Project View.

Finally I thought that I would try creating a purely local controller in the main app; I did that and at the end of the process IDEA suddenly found the other two controllers, so there are now three correctly located, all under the main app's controllers directory: one under the main app's package sub-directory and the other two under the plugin package sub-directory.

So it does seem to me that there is something in IDEA that is not correctly analysing the directory/package structure under a Grails application  for anything other than a straightforward situation.


Comment actions Permalink

Another update: I discovered that if instead of using the sort-of drop-down Generate Controller option (available when editing the domain class) I actually use the run grails command generate-controller and specifically enter packagename.classname then the controller is created correctly AND displayed immediately in the Grails/Project View.

So perhaps it really is something to do with IDEA and packages ?

Is this a bug, and shall I raise a bug ?

It seems to me that there is little point in having the "Generate Controller" facility if they cause this sort of problem; they are presumably meant as an improvement to using the Run grails command option but it's hardly much use if you have to do extra work to get the details displayed. This may probably apply to Generate VIews, I haven't tried them yet.



Please sign in to leave a comment.