shuttsy
shuttsy

Reputation: 1645

Using Grails projects for common code and dependencies to other Grails projects

Is it possible or recommended to have/use Grails projects as common dependencies for other Grails projects?

Say I have grails-1 project which contain the concept of a User service (i.e. domain classes for User, SecUser, SecKey objects, exposed services (via HTTP exporter) in order to authenticate/login/logout and some pages/controllers to manage the CRUD on these domain objects for an admin user, etc).

Now say I have a grails-2 project which also has the same concept of a User service.

Both my projects at runtime at seperate from each other which different databases. So no shared runtime instance of the User service is suitable.

So I was thinking of moving all the User functionality into a common-user Grails project which is packaged as a war then grails-1 and grails-2 have a dependency on this (as they will wish to use domain classes/services in their functionality).

Then for svr-1 I deploy wars common-user and grails1, srv-2 has common-user and grails-2.

Will that work?

Or is there a way to reference common-user as a compile dependency in grails-x which in affect will package all it's objects in the grails-x war?

Upvotes: 3

Views: 199

Answers (2)

Bob Yang
Bob Yang

Reputation: 163

You can put the domain classes or other common classes into a grails plugin, then use the plugin in multiple grails projects or even non-grails projects because for grails v4 the plugin is just a regular jar.

See grails-multi-project-build for configuration details.

Upvotes: 0

Joshua Moore
Joshua Moore

Reputation: 24776

This is exactly the reason to use inline plugins for common functionality. Create your shared functionality as a Grails plugin then you can include it in your grails projects as an inline plugin within the BuildConfig.groovy (see below). I have had great success using this pattern in several Grails projects.

BuildConfig.groovy

grails.plugin.location."my-shared-plugin" = "../my-shared-plugin"

Upvotes: 2

Related Questions