Grails 3 Plugins and watchedResources

100 views
Skip to first unread message

Ken Siprell

unread,
Mar 22, 2015, 1:40:05 PM3/22/15
to grails-de...@googlegroups.com
Can someone verify that watchedResources is working correctly in a Grails 3 plugin? I'm not having any luck. I've searched grails-core and checked the grails3-plugins, but I didn't find anything helpful.


When I edit and save a watched file it's recompiled, but the onChange method is not called.

Thanks,
Ken

Bud Byrd

unread,
Apr 6, 2016, 10:24:42 PM4/6/16
to Grails Dev Discuss
Reviving this one. I'm having a similar problem where watched resources are not triggering a plugin's onchange method. I know that Grails is reloading the object because there's logging when the artefact handler fires, but I'm never seeing the onchange work. Before I start posting code, I just want to know, is the onChange functionality with hot loading actually working? I'm using Grails 3.1.4.

Bud Byrd

unread,
Apr 6, 2016, 11:15:58 PM4/6/16
to Grails Dev Discuss
Digging through the Grails source code with the use of the intellij debugger, I found this little gem: AbstractGrailsPluginManager.informOfClassChange. It looks like it first finds the artefact handler for the reloaded artefact type, and if it exists, tries to retrieve the plugin by the same name as the artefact type. Only if it finds a plugin with the same name does it fire off an EVENT_ON_CHANGE event, which triggers the onChange method call.

A couple questions then. I may have missed it, but I didn't see anything in the documentation that stated that artefacts needed to match the name of the plugin. If that's truly the case, that breaks previous Grails behavior, especially when a plugin creates more than one artefact type. Second, does this also mean that only one plugin can be notified of a watched class reload? This also breaks previous behavior.

My apologies if I've misunderstood the logic here, and any help would be appreciated.

Bud Byrd

unread,
Apr 6, 2016, 11:45:12 PM4/6/16
to Grails Dev Discuss
So it looks like I went down a rabbit hole with the previous post that didn't help me much. Looks like that has to do with spring loaded and it is not the only trigger for the onchange stuff to occur.

It looks like the culprit for onChange not firing has to do with GrailsApp.enableDevelopmentModeWatch. I'm not sure why, but the logic in the loop will only fire off the onchange event if the changed file is also a new file. From the Grails 3.1.4 source, see line 222. I'd have guessed this logic was reversed, but if the changed file is also a new file, there's a line that removes that file from the new files list, and then it submits the file change event.

Whatever the reason for this, the end result is that my plugin's onChange method is not being trigger for a file that is being watched. I've confirmed through debugging that the watched files list is being loaded correctly, and I'm not sure where to go from here. If my understanding of the above is wrong, my apologies. If this sounds like a bug, I'd be happy to submit a JIRA.

Also, I'd really like to understand how a changed file can also be a new file, and why onChange will only fire if both are true.

Thanks for any help.

Bud Byrd

unread,
Apr 7, 2016, 10:25:09 AM4/7/16
to Grails Dev Discuss
I've submitted an issue on the grails-core project in Github. You can find it here: https://github.com/grails/grails-core/issues/9848.
Reply all
Reply to author
Forward
0 new messages