Franz See
Franz See

Reputation: 3382

Common backend Grails application

I have a Grails Application AppA. And I am planning to create a new Grails Application AppB, wherein AppB practically uses the same services and models of AppA.

How should I approach that?

  1. Extract a Grails Application AppC which would have the common services and expose that service as a remote/web/rest service?
  2. Extract a Groovy project ModC that will be a jar containing the common services and models and have AppA & AppB depend on ModC?
  3. Just git clone and cherry-pick every now & then?
  4. Other suggestions?

Note that AppA have some lazy-loaded relationship invocations (i.e. entity1.entity2.entity3.propName) & GORM invocations (i.e. Entity1.get(1L)) from the presentation layer (controllers & views) as well. Although I can probably push some of them back to the services, I'm concerned about the refactoring effort to have the relationship invocations from the view remain intact (i.e. I would need to eager loaded some associations, or create Data Transfer Objects)

Upvotes: 2

Views: 363

Answers (4)

Jan Wikholm
Jan Wikholm

Reputation: 1575

The Grails way to share common functionalities, utilities and whatnot is to make a plugin that encapsulates those and install it to both projects.

A plugin can contain anything you can put in a regular Grails app -- i.e. Models, Service, Views, Controllers, config files, resources under web-app etc.

You can then either release it to an internal svn repository or just use it with package-plugin

Edit:

One way to do it while you are constantly updating the code is to have it as an inline plugin. So remove the plugin from your application.properties and add:

grails.plugin.location."name-of-plugin" = "/path/to/plugin/dir" // or "../plugin/"

This removes the necessity of reinstalling the plugin all the time. But this is for development time only.

Upvotes: 5

Jarred Olson
Jarred Olson

Reputation: 3243

I had this situation on a previous project and we used a plugin project to hold our common functionality and it worked really well. I don't think a jar file would work well since as far as I know you wouldn't be able to take advantage of things like auto-wiring dependency injection of services, the domain/GORM/dynamic finders on domain objects, etc.

Upvotes: 1

omarello
omarello

Reputation: 2693

Have you considered the option of separating your models and services (the ones used by both apps) into a plugin. I think that is the prefered way at least from what I have been following within the community.

You can take a look at this link. It is not exactly equivalent to your case, but should give you a good idea for the plugin approach.

Upvotes: 1

zoran119
zoran119

Reputation: 11307

I think I would put the functionality into a separate jar and use it in the two applications (so your suggestion no 2). I wouldn't make a new application (suggestion 1) because you just need some services not a whole web application, and I wouldn't do suggestion 3 because the services wouldn't be as reusable as with suggestion 2.

Upvotes: 0

Related Questions