Skip to content

Grails 3, Eclipse and exploded plugins (aka sub projects)

June 29, 2017

Any medium to large project is likely to need more than one grails app.  E.g. a web admin app and an API app.  Each is a war file deployed to different servers with different firewall rules and security.   Both share the same services and domain objects.

With grails 2.5 life was easy, you just created an app and an exploded plug in with the common services and domain objects the same root dir, added one line to the app to be dependent on the plugin, and IDEs just picked it up and worked.  You could run the app from command line or within GGST or intellij and any changes to files in the core plugin and the app would both auto-load.

Getting this to work with Grails 3 has been tricky.  This post has a complicated solution which would not play nice with eclipse.  The official manual has some recommendations.

Firstly, setup eclipse like this.  Grails 3.2 and eclipse Neon 4.6

Secondly, create your project root directory, e.g. “myProject”

Thirdly, in the myProject directory, create two grails projects thusly:

$ grails create-app web-admin --profile=web
$ grails create-plugin core

Fourthly, edit the web-admin/build.gradle and add the following lines:

grails { exploded = true
        plugins { compile project(':core-services') 

This is more or less the same as for 2.5.

at this point you can go into web-admin and run “grails run-app” and it works.

Now lets go and create a domain object in the core project:

$ cd ../core-services
$ grails create-domain-class

Filthy, add settings.gradle

$ cd ..
$ echo "include 'web-admin', 'core-services'" >> settings.gradle

Now win you do “grails run-app” in the web-admin project, you should see 1 domain under artifacts in the web page at http://localhost:8080

The final piece is to get this working in eclipse.

In eclipse, under File->Import->Gradle->Existing Gradle Project, chose the root directory (the one above the two projects).

You can even run the project by selecting web-admin->application->bootRun in the “Gradle Tasks” window, although I have not checked yet if the auto loading works this way.

Note, if you want to generate static copies of scaffolded controllers for domain objects, you will need to do it in the core plugin project, then move the resultant files to the web project.

e.g. if you want to run “grails generate-controller Book” you need to do this in the root folder of the core plugin project, then move BookController.groovy to the web project.


From → dev

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: