Newbie: how to share domain class between multiple projects

225 views
Skip to first unread message

Brian Lawson

unread,
Feb 12, 2015, 10:44:00 AM2/12/15
to grails-de...@googlegroups.com
I'm new to Groovy/Grails and I'm working on a couple of simple projects that should both use the same database table.  I created one project which allows users to enter ideas and solutions for how to improve our campus.  I now need to develop another application that uses the same data.  So how can I leverage the domain class from the 1st project into the 2nd?

I'm using IntelliJ if that helps at all.

Thanks

Dominic Fui Dodzi-Nusenu

unread,
Feb 12, 2015, 11:26:25 AM2/12/15
to grails-de...@googlegroups.com
Honestly, I have pondered over this for a while. Most blogs talk about code modulization in grails by using plugins, but I don't find that structure or method to be useful since it requires maintaining a folder for both projects to give them access to the local plugin, located on the file system.

A more scalable method is to have the domain directory as a submodule in your cvs (git) repository and anytime there is an update both projects will update the submodules and have the changes. I am yet to test the scalability of this approach so don't take it whole heartedly.

I don't know if you could combine the plugin structure with a submodule git repo structure which could be more effective accross board. Let us know how you implement this.
--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/10d77be4-3aae-44ed-aafe-2fa5dd51b224%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
Fui Nusenu
twitter: @daptordarattler

Brian Lawson

unread,
Feb 12, 2015, 12:45:24 PM2/12/15
to grails-de...@googlegroups.com
I agree that having multiple copies of the code that must be updated each time can cause quite a bit of problems.  My current project is a small/easy one.  I'm concerned about how this scales with larger mor complicated applications.


On Thursday, February 12, 2015 at 10:26:25 AM UTC-6, Dominic Fui Dodzi-Nusenu wrote:
Honestly, I have pondered over this for a while. Most blogs talk about code modulization in grails by using plugins, but I don't find that structure or method to be useful since it requires maintaining a folder for both projects to give them access to the local plugin, located on the file system.

A more scalable method is to have the domain directory as a submodule in your cvs (git) repository and anytime there is an update both projects will update the submodules and have the changes. I am yet to test the scalability of this approach so don't take it whole heartedly.

I don't know if you could combine the plugin structure with a submodule git repo structure which could be more effective accross board. Let us know how you implement this.


On 02/12/2015 03:44 PM, Brian Lawson wrote:
I'm new to Groovy/Grails and I'm working on a couple of simple projects that should both use the same database table.  I created one project which allows users to enter ideas and solutions for how to improve our campus.  I now need to develop another application that uses the same data.  So how can I leverage the domain class from the 1st project into the 2nd?

I'm using IntelliJ if that helps at all.

Thanks


-- 
Fui Nusenu
twitter: @daptordarattler

Robert Oschwald

unread,
Feb 12, 2015, 1:10:46 PM2/12/15
to grails-de...@googlegroups.com
I use plugins for shared code which are deployed to an Artifactory private repo.
During development, the plugins are -SNAPSHOT versioned and the projects use "updatePolicy: ‚always‘ on the plugins-snapshot repository definition in BuildConfig.groovy to always get the latest version.

This way, I’m quite fast in developing the shared code and use them in several microservice Grails applications.


Robert
> --
> You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
> To post to this group, send email to grails-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/bf3d2f5f-bd94-4575-a4b7-a2e14566c275%40googlegroups.com.

Brian Lawson

unread,
Feb 12, 2015, 4:54:21 PM2/12/15
to grails-de...@googlegroups.com
So how does one go about creating a plugin?


On Thursday, February 12, 2015 at 12:10:46 PM UTC-6, Robert Oschwald wrote:
I use plugins for shared code which are deployed to an Artifactory private repo.
During development, the plugins are -SNAPSHOT versioned and the projects use "updatePolicy: ‚always‘ on the plugins-snapshot repository definition in BuildConfig.groovy to always get the latest version.

This way, I’m quite fast in developing the shared code and use them in several microservice Grails applications.


Robert






> Am 12.02.2015 um 18:45 schrieb Brian Lawson <brianle...@gmail.com>:
>
> I agree that having multiple copies of the code that must be updated each time can cause quite a bit of problems.  My current project is a small/easy one.  I'm concerned about how this scales with larger mor complicated applications.
>
> On Thursday, February 12, 2015 at 10:26:25 AM UTC-6, Dominic Fui Dodzi-Nusenu wrote:
> Honestly, I have pondered over this for a while. Most blogs talk about code modulization in grails by using plugins, but I don't find that structure or method to be useful since it requires maintaining a folder for both projects to give them access to the local plugin, located on the file system.
>
> A more scalable method is to have the domain directory as a submodule in your cvs (git) repository and anytime there is an update both projects will update the submodules and have the changes. I am yet to test the scalability of this approach so don't take it whole heartedly.
>
> I don't know if you could combine the plugin structure with a submodule git repo structure which could be more effective accross board. Let us know how you implement this.
>
>
> On 02/12/2015 03:44 PM, Brian Lawson wrote:
>> I'm new to Groovy/Grails and I'm working on a couple of simple projects that should both use the same database table.  I created one project which allows users to enter ideas and solutions for how to improve our campus.  I now need to develop another application that uses the same data.  So how can I leverage the domain class from the 1st project into the 2nd?
>>
>> I'm using IntelliJ if that helps at all.
>>
>> Thanks
>>
>
> --
> Fui Nusenu
> twitter: @daptordarattler
>
>
> --
> You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.

Søren Berg Glasius

unread,
Feb 12, 2015, 6:29:27 PM2/12/15
to grails-de...@googlegroups.com
Hi Robert

you start by 

grails create-plugin YourPluginName

It will create a project that looks mostly like a grails application but with some of the unneeded files not there

To quickly start using your plugin in a grails app and to develop it with class reloading, you could add this to your Grails App BuildConfig.groovy file:

grails.plugin.location.'yourPluginName'='../yourPluginName'

given that your plugin and your grails app is in the same directory.

If you use IntelliJ it will automatically recognize this as an inlined plugin

Hope this helps!


Best regards / Med venlig hilsen,
Søren Berg Glasius

40 Stevenson Ave, Berkeley, CA 94708
Mobile: (+1)510 984 8362, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.

To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.

To post to this group, send email to grails-de...@googlegroups.com.

Bill Baran

unread,
Feb 13, 2015, 7:53:51 AM2/13/15
to grails-de...@googlegroups.com
Why not put the domain in a maven project and build it as a jar and import it?

WKBaran

Brian Lawson

unread,
Feb 13, 2015, 9:02:05 AM2/13/15
to grails-de...@googlegroups.com
Because I'm new to Groovy/Grails and have no idea what a maven project is. (Shrugging my shoulders)

Brian Lawson

unread,
Feb 13, 2015, 9:03:10 AM2/13/15
to grails-de...@googlegroups.com
So what goes in the plugin?  The domain class I assume, but what about controllers, views, etc.?  Do they go in the separate apps?

Bill Baran

unread,
Feb 13, 2015, 11:16:27 AM2/13/15
to grails-de...@googlegroups.com
Maven is far simpler than grails. You can learn it in a 1/2 hour.
To each his own.

Bill

On Fri, Feb 13, 2015 at 7:03 AM, Brian Lawson <brianle...@gmail.com> wrote:
So what goes in the plugin?  The domain class I assume, but what about controllers, views, etc.?  Do they go in the separate apps?

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/_uzpL-q8LTc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grails-dev-disc...@googlegroups.com.

To post to this group, send email to grails-de...@googlegroups.com.

Brian Lawson

unread,
Feb 13, 2015, 1:22:36 PM2/13/15
to grails-de...@googlegroups.com
honestly, I don't particularly like Groovy/Grails so far, but management decisions dictate what I do, so...
I'd rather do this in PHP

Søren Berg Glasius

unread,
Feb 13, 2015, 1:37:39 PM2/13/15
to grails-de...@googlegroups.com
Hi Brian,

If the controllers are strictly for a domain class in your plugin, you can put it in the same plugin. Same goes for the views.

When you use your plugin, and you create controllers and/or views with the same names, you will replace those of the plugin, as the search order in Grails is: App -> Plugin -> Grails Core




Best regards / Med venlig hilsen,
Søren Berg Glasius

40 Stevenson Ave, Berkeley, CA 94708
Mobile: (+1)510 984 8362, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.

On 13 February 2015 at 06:03, Brian Lawson <brianle...@gmail.com> wrote:
So what goes in the plugin?  The domain class I assume, but what about controllers, views, etc.?  Do they go in the separate apps?

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.

Brian Lawson

unread,
Feb 13, 2015, 2:35:43 PM2/13/15
to grails-de...@googlegroups.com
Here's my situation:

I need one application to allow users to enter details (I'm calling it Idea), view previously entered Ideas by other people, and any responses to those Ideas.
These users are initially presented with a list of visible Ideas and can click on each one to read-only the details.  Also, these users can edit/update there Ideas unless it has already been responded to.

I need an "admin" application to allow the admin user to enter a response or select a "hide" checkbox that will not show that set of details to the public.
These users are initially presented with the same list except that they will have a "hide" and an "edit" button for each Idea.

So I have the same Idea class and only the civilian users can enter data and admin users can only respond and/or hide the Idea; both can update, but only the admin users can edit the response.

So, can each application link in the domain class in the plugin but have their own controllers and views for the domain class?


On Friday, February 13, 2015 at 12:37:39 PM UTC-6, Søren Berg Glasius wrote:
Hi Brian,

If the controllers are strictly for a domain class in your plugin, you can put it in the same plugin. Same goes for the views.

When you use your plugin, and you create controllers and/or views with the same names, you will replace those of the plugin, as the search order in Grails is: App -> Plugin -> Grails Core




Best regards / Med venlig hilsen,
Søren Berg Glasius

40 Stevenson Ave, Berkeley, CA 94708
Mobile: (+1)510 984 8362, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.

On 13 February 2015 at 06:03, Brian Lawson <brianle...@gmail.com> wrote:
So what goes in the plugin?  The domain class I assume, but what about controllers, views, etc.?  Do they go in the separate apps?

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.

To post to this group, send email to grails-de...@googlegroups.com.

Bill Baran

unread,
Feb 13, 2015, 3:30:20 PM2/13/15
to grails-de...@googlegroups.com
Oh sorry I was thinking something other than grails domain objects.
That has to be a plugin.

WKBaran

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/_uzpL-q8LTc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grails-dev-disc...@googlegroups.com.

To post to this group, send email to grails-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages