views:

293

answers:

2

Hi,

I have a Grails app consisting of main app and its local module linked in BuildConfig.groovy:

grails.plugin.location.'mymodule' = "modules/mymodule"

In mymodule I would like to use Helper classes from the main app, however I cannot find any way of how to make mymodule dependent to the main app. I was thinking of adding some extra part to the classpath for mymodule compile, but I'm stuck here.

Any idea how to do this?

+1  A: 

You cannot do what you are trying to do, at least not easily. It's a one-way dependency from the plugins, which are compiled first. The only way to do it is to create a call-back mechanism in your plugin that you can register against. This way, your app will register itself with the plugin and plugin will call the classes when needed.

Think of plugins and their dependencies as jars - you cannot download a jar from some library and expect it to call your code, unless it's designed that way.

If you have helper classes, assuming they don't depend on anything in your main app, I'd suggest you move them from main app to a separate plugin that your local plugin depends on. This way both your main app and your local plugin depend on the helper classes. Or just move the helper classes to the plugin in the first place - they will then be available to both the plugin and main app.

Jean Barmash
Yep, this is the solution for app with one module, but what if I need more modules in the app and all should be using that same helper class?
Pavel P
Same thing applies. You have to have a module / plugin that gets compiled / loaded first before any other modules (you can enforce the order using dependsOn and loadAfter in plugin definition file), or you have to have ability to do callbacks for all of them. Here is docs for defining dependencies - http://www.grails.org/Plugin+Dependencies
Jean Barmash
A: 

Let me see if i follow - in his setup (mine is the same) you would edit application.properties to include the shared plugin as a dependency in both the local plugin and the core app- is this best practices? does the plugin get "installed twice"? it seems to be installed in two locations

I'm simply looking to use the spring security plugin across the core app and several local plugins