I just spent a couple hours trying to figure out why my Grails views wouldn’t match up with my domain.
This started out when I decided that I wanted to simplify my domain model and remove an item, DependencyVersion, from the middle of the hierarchy. This required the removal of the domain object and the update of higher and lower levels to fill in the gap. I am still in the early phases and haven’t started customizing my views much so the easiest thing to do (for me at least since I am a newbie to Grails – there may be a better way – speak up gurus) was to blow away the domain object, the test object, all the controllers, and all the views. I then ran my script, that simply called “grails generate-all X” for each domain object in my project, and generated new views. I then started my server, only to be greeted by a message trickling up from Hibernate regarding the DependencyVersion class being missing but being used in an association.
My domain no longer had this class. I could even do a text search on the entire project for “DependencyVersion” and get no results. I tried everything I could think of – I won’t list it all here – but finally found out that the actual bug was resulting from grails caching the build and not updating it properly. When you run “grails generate-all X” it builds the domain classes and places them in the Documents and Settings folder. In my case, this resulted in my project being built here: C:\Documents and Settings\jmcdonald\.grails\1.0-RC4\projects.
I blew this folder away, ran my script again, and Voila!, it worked. So am I missing something or is this a bug in Grails? I am very new to Grails and am thinking there is probably an explanation…
Thanks Kevin – I had not discovered the clean target yet.
I am using IntelliJ 7, which I think may be part of the problem. I wasn’t aware that grails would build to its own directory so my IntelliJ build and the command line build were going to two separate places. I did multiple cleans through IntelliJ but it obviously wasn’t hitting the grails folders. I just started using this version of the IDE since it has RoR and Grails support but I haven’t learned all the nuances yet and find myself switching back over to the command line pretty frequently.
try running: grails clean
You probably had a compiled copy of the DependancyVersion class in the .grails\1.0-RC4\projects folder. I think grails uses it as some kind of cache.
hope that helps
Are you using an IDE to write your code? I know eclipse (used to) compile classes into the project root – not very good – you’d change the groovy file but wouldn’t see the change until you deleted the class file. I think that’s been fixed for a while though.