开发者

Convert grails app to plugin

开发者 https://www.devze.com 2022-12-26 07:01 出处:网络
I started a grails application by grails create-app. For modularity, I feel like it would b开发者_开发百科e better that component be a plugin. Can I convert this application into a grails plugin?

I started a grails application by grails create-app. For modularity, I feel like it would b开发者_开发百科e better that component be a plugin. Can I convert this application into a grails plugin? thanks, Babu.


I never created a plugin based on an application written before but looking at the documentation for grails plugins you can read the following statement:

The structure of a Grails plugin is exactly the same as a regular Grails project's directory structure, except that in the root of the plugin directory you will find a plugin Groovy file called the "plugin descriptor".

So I would suggest to create a new plugin with grails create-plugin *your-plugin-name* and copy all files from your application into the plugin.


In case anyone else is looking, this should be exactly what you need: http://burtbeckwith.com/blog/?p=1973

Excerpt:

So to convert an application to a plugin, the general workflow would be something like

  • Create the plugin descriptor, FooGrailsPlugin.groovy. The easiest way to do this is to rungrails create-plugin pluginname and copy the generated file from there

  • delete everything from application.properties except the app.grails.version property

  • if you have jars in the lib directory that are available in a Maven repo, delete them and replace with BuildConfig.groovy dependencies

  • change any plugin and jar dependencies that are needed for development and testing but not when the plugin is installed to not be exported, by adding export = false

  • If you need the _Install.groovy, _Uninstall.groovy, or _Upgrade.groovy scripts (you probably don’t) grab those from the dummy plugin from step 1 (but delete any you don’t need, they’re all optional)

  • delete ApplicationResources.groovy if you aren’t using it and don’t depend on resources plugin

  • move code from BootStrap.groovy init() toFooGrailsPlugin.doWithApplicationContext and/orFooGrailsPlugin.doWithDynamicMethods and destroy() to FooGrailsPlugin.onShutdown, and delete BootStrap.groovy

  • add a dependency for the release plugin in BuildConfig.groovy

  • delete everything but the log4j configuration from Config.groovy

  • delete UrlMappings.groovy unless you have exported mappings; only keep the added ones

  • move bean definitions from resources.groovy to FooGrailsPlugin.doWithSpring and delete resources.groovy

  • delete grails-app/i18n message bundle files unless you added messages; only keep the added ones

  • delete everything from grails-app/views that you don’t use (in particular error.gsp,index.gsp, and layouts/main.gsp)

  • delete everything from web-app that you don’t use (including WEB-INF xml and tld files)

  • now would be a great time to write those tests you’ve been meaning to get to

  • create one or more test applications to install the plugin into to ensure that it works as a plugin; consider scripting this

  • write documentation for how to use the plugin; at a minimum a README file, but Grails gdoc files would be much better (run grails doc --init to get started)

0

精彩评论

暂无评论...
验证码 换一张
取 消