In a Groovy application, if you want to initialize metaclasses, where is the best place to put those initializations? In Grails apps, I've used the Bootstrap.groovy file. Is there something similar for an arbitrary Groovy app?
Edit: To clarify, I'm looking for a non-intrusive way of doing this that will guarantee it gets called when running the main application as well as in unit tests of the associated code.
There's nothing like Bootstrap.groovy for standard groovy applications, but that doesn't stop you doing the same thing in your app and having a class or method that is called once on startup where you can add the metaClass initialization
Added from comments below:
You can write a DelegatingMetaClass for each class you wish to decorate, and place it in the package groovy.runtime.metaclass.[YOURPACKAGE].[YOURCLASS]MetaClass
This page explains the steps required to do this (2nd item on the page)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With