Saturday, April 16, 2016

Big Gotcha with Adding New Artefact Type to Grails

I just recently lost a day fighting some issues with Grails and a custom artefact in my plugin development.  The cause was simple: some classes must be Java classes to work correctly.

I followed the format of the quartz plugin and created my own versions of the artefact handlers and such.  I missed that some of the files were .java files:

  • DefaultGrailsJobClass.java
  • GrailsJobClass.java

My clones of those two files were .groovy files.

Of course, I started getting weird results like stack over flow exceptions and methods not found (e.g. getName()).  Even getClass() would fail with a stack over flow.

It turns out Grails is using some metaClass magic with the artefact class DefaultGrailsJobClass, and you just can't use Groovy for them.  I causes the Grails magic to get stuck.

Also, you can store these .java files under the src/main/groovy without problems.

As usual, when you deviate from the Grails approach, odd things jump up and bite you...

No comments:

Post a Comment