In order for Grails to support reloading of classes without causing problems with cached instances in application and session scope I need Groovy to support a loadClass method that reloads a class if it has been changed.
Ideally it needs to interact with the GroovyResourceLoader to load resources as Urls if possibly.
Something like
gcl.loadClass(final String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve, boolean reload)
would be ok.. otherwise maybe a different method
gcl.reloadClassIfNecessary(String name) maybe ?
gcl.reloadClass(String name, boolean force) // for forced reload or false to return current if no changes?
I've attached the test case I used to test this out originally in Grails. It is not Grails specific so you should be able to drop it into groovy and just change the package names
It looks like when a groovy class is a subclass of another groovy class, the reloading doesn't work since it doesn't see the GroovyObject interface. I've created a simple patch to descend the inheritance tree. Seems to work fine with the patch.