Question

Plugins in Grails are great method to modularise an application.The documentation suggest to override the artifacts from the plugin in the application, which uses this plugin.

Is it realy the best approach?

Let's describe it by example: There is a domain class "org.User" defined in the plugin. The application overrides this domain class. If I use "grails run-app" then there are no warnings and it works. But Eclipse (GGTS) complains about "Invalid duplicate class definition of class org.User". For some developers it wouldn't matter, but I like the IDE helping on coding by stuf like "autocomplete".

At the end both classes are compiled an put on the java class loader. The application version of the class is loaded before the version of the plugin. The class resolver finds it first and that's why it works. Please correct me if I'm wrong at this point. Is it realy a good idea to have two versions of a class in one class loader?

What are the alternatives?

Was it helpful?

Solution

You can do like Spring Security Core plugin does, provide the User class as a template, so your application that use this plugin can choose between creating his own class or installing your default User class.

The plugin user template is here, and the script responsible to create this in the application is here.

You will need also a config value to know the class to use, and use it dynamic.

P.S: there are good security plugins like Shiro and Spring Security, maybe it's easier to check them instead of create your own.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top