简体   繁体   中英

How to setup local dependency in grails plugin (classpath to the main app)?

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM