简体   繁体   中英

Use grails plugin outside of grails framework?

Is it possible to use a grails plugin outside of the grails framework?

Plugins that depend on Grails itself obviously don't qualify, but assuming a plugin depended only on non-grails libraries, is there a way to use a packaged plugin, as-is, in stand-alone groovy or Java app?

Intent

We have a LOT of functionality in Grails plugins, and we're thinking of using springboot for standalone groovy applications, so reusing the functionality in those plugins is important. I know Grails 3 is moving to springboot, but we're not holding our breath.

A packaged Grails plugin appears to contain only groovy source files, so I suspect this will work for groovy-based projects, though more difficult for pure Java projects.

I would guess the answer to this is "probably not" for the reason that your requirements specify something that shouldn't exist, but might. Why would a plugin be a plugin if it didn't require some measure of Grails libraries, processes, etc. If a plugin is just code, then it should really just be a jar.

That said, maybe there are plugins with just some Groovy classes in them. In that case, as long as you also manage to add their dependencies to your project, it shouldn't be that difficult to take the code for the plugin and convert it to compile into a jar instead, then depend on that jar (and its dependencies) in your project.

Be careful, as many plugins also depend heavily on Grails' Spring dependency injection. As you plan on using Spring Boot, that shouldn't be too difficult to recreate in your project, as the doWithSpring block in the plugin's descriptor should give you a good idea of what beans are needed. You should also look out for Grails-convention autowiring. If the plugin has a controller or service with a member named fileService, then you'll need to make sure that controller has a fileService injected when it's instantiated, just like Grails would do.

Finally, the directories in the plugin in which you find the classes in question are also important. Grails treats and loads classes from different directories in different ways (think Filters, Events, Jobs, etc.), which you would no longer get automatically. A plugin with some of these in it would take special handling when brought into a non-Grails project.

So, without knowing which plugins you're trying to use the classes out of, it's hard to say whether what you want is possible. I still think that most of the plugins people use actually require some Grails-like environment in which to run. That could be Grails, or something you set up that works similarly in Boot (good luck!)

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