Access domain class of main project inside custom plugin project - grails

I am working on a project which is further subdivided into plugin projects. So I include all plugins inside Main project and it works.
Now there are few domain classes like User which are inside Main project. I am trying to access it inside my custom plugin project.
Note: I am not trying to access Plugin's domain class inside main project but reverse of it.
Thanks.

It is not possible to reference application classes in a plugin. If you think about it because a plugin should be an independent functionality, that can be plugged in any application.

Related

using the domain objects in one grails project as a dependency in other grails project

I have created one grails project that contains all the foundational domain objects. I want to create separate grails projects so it helps me to keep the functional boundaries separate , but, I have a need to use these foundational domain objects and services as a base dependency so i can use this layer seamlessly in all of my other grails project. Any thoughts on if this is a right approach and some pointers on how to go about doing it is highy appreciated
You can make the one, having domain classes, a plug-in, instead. Then, use that plugin in your actual app.
See the docs, especially the section, Plugins and Multi-Project Builds.

Can I create Domain classes in separate Java Project and import in Grails

Just for flexibility and not to be tied up with Grails, I wish to create domains on a separate java project and import the domain classes in Grails project. Is that possible? I am thinking the Java project will just contain POJO and maybe hibernate mapping to database.
I wish to be able to use the usual save delete and find* functionalities if possible.
You need to create a separate plugin project which contains the domain classes. And if you want to use it in your grails project then just add following in your BuildConfig.groovy
grails.plugin.location.YourDomainClassProjectName= "../YourDomainClassProjectName"
And add that project from build path. Right click on project from navigator - > Properties -> Java Build Path -> Project ... and add your project here.
You can use also plain Java project as a domain model - see grails.org/doc/latest/guide/single.html#hibernate
Basically you put there your domain classes together with Hibernate mapping (XML or annotation-based) and pack it into jar, which is then added as a dependency to the grails app.
Your domain classes will be enhanced with standard GORM methods (findBy, save..) just as if they were GORM domain classes. We have used this model a long time in our projects.

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?
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"
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.

Is there a workaround for not including custom activities in build controller?

I need some assistance with developing custom activities for TFS build. I have followed the steps in blog post Customize Team Build 2010 – Part 7: How is the custom assembly found?.
I have created a custom activity built into a DLL file and used in build template. I want to set it up in the TFS build now, but I have run into some issues. In the blog it suggests that the custom activities DLL file be referenced via the build controller. However, this is an issue for me. I work in a company where there are numerous projects and all use the same build controller. Therefore I don't have the permissions to make the change suggested in configuring the version control path to the custom activity.
Is there are another option open to me? Is there another way I can reference the custom activities? In the build template maybe?
You need to get that assembly onto the build server (build agent server assuming the activity is only used within the Run On Agent activity).
The most convenient option is to simply check it into the TFS folder that the build controller is pointing to for build assemblies, and the controller will automatically push it out to all build servers.
Alternatively, if you have direct access to the Build Agent Server(s) you can manually install the assembly onto the server into the GAC.

How to add plugin project as a dependency to my main projects

My requirement is as below:
I will be having three projects.
Main project (Grails project)
Main project adaptor (Grails project)
Domains plugin project (Grails project)
Domains plugin project will be having all of the domain classes and its test cases in it. So, I want to use those domain classes in other two projects. Here, I want to build Domains plugin project first, and the output of this build project should be the dependency of other two projects. I should be able configure this in BuildConfig.groovy.
Presently, I have done in the following way:
Created a plugin project using create-plugin and followed by package plugin command. Now, I kept that ZIP file in my lib folder and configured in Build-config.groovy. This works as expected. But, when ever I change domain classes, I need to do lot stuff. Like coping it to lib.
Is there any possibility to do in the first way I explained..!! Please help me out in this..!!
Thanks in advance
You can use inline plugins - put all of your three projects at the same level (in the same directory) and then configure adaptor and domain plugin as inline plugins in Main project.
That way you dont have to build each project separately, you can do changes in your domain plugin or adapter and they will get picked in main project automatically.
Inside your main project's BuildConfig.groovy
grails.plugin.location.'adapter' = "../path-to-adapter-plugin"
grails.plugin.location.'domain' = "../path-to-domain-plugin"
Note - putting all three projects at same level isn't required, but doing that will let you use relative paths - but if you want you can use absolute paths as well

Resources