Another way of adding local Grails plugin to a Grails app using the Gradle build tool

Shashank Agrawal
WizPanda
Published in
3 min readFeb 24, 2020
https://pixabay.com/photos/tools-construct-craft-repair-864983/

Grails is an under-rated yet a powerful Groovy-based web application framework which is built on top of Java + Spring + Hibernate (can be customized, though).

Grails 3+ build system solely uses Gradle build tool so basically a Grails app is a Gradle app too.

If you see the file structure of a Grails app, you will see that it is backed by a Gradle file structure having a build.gradle, settings.gradle, gradle.properties etc.

This means, if you want to do any kind of customization in your build tool, you can always google in context of a Gradle app when you don’t find it in context with a Grails app (I said, Grails is an under-rated app but we love it 😍)

That being said, if you are writing or developing a Grails plugin (which is another super cool way of making your code DRY) and you want to install it locally in your any Grails app, the documentation says that you can do this:

grails install

This will publish a local version of the Grails plugin in your local maven cache. And then you can use it in your Grails app like:

compile "com.example.plugins:foo-bar:1.0.1"

This is nice but it creates a few developers pain (I’m giving it a name 😂):

  1. Repetitive Pain: Every time you do changes in your Grails plugin, you’ll have to run grails install and then restart your Grails app to see the changes in action.
  2. Confused Pain: Consider your foo-bar plugin was already released with a version of 1.0.1 and after some local changes, you ran grails install and then, later on, you might find yourself spending time on a very weird issue. 😳 Wants to know what that will be? Share this post and tag us on our LinkedIn page and I will write another blog explaining this in detail.

Let’s solve these problems in Gradle way (as I mentioned, every Grails app & Grails plugin is a Gradle app).

In Gradle, you can reference any local directory as a compile-time dependency. For this, you need to add the two lines in your settings.gradle file (if not there, create one) of your Grails app:

include ':foo-bar'
// Relative path to foo-bar plugin
project(':foo-bar').projectDir = new File('../foo-bar')

(Considering, your Grails app & Grails plugin resides in the same directory as siblings)

Now, in the build.gradle file of your Grails app, comment any existing reference to your foo-bar plugin and add the following:

grails {
plugins {
compile project (':foo-bar')
}
}
// Another waydependencies {
// ... other dependencies
compile project (':foo-bar')
}

That’s it! 😎

🎉 Super easy huh..!!

Benefits of this approach:

  1. Anytime you make changes in your Grails plugin code, you don’t have to run grails install (solving the repetitive pain).
  2. This is not going to pollute your local Maven/Gradle cache (solving the confused pain).
  3. The biggest benefit is that you will get hot-reloading of changes like you get while developing a Grails app that means any changes that you make will be immediately reloaded in your Grails app without restart the application.

Want to see your amazing idea in action? Or want to join us? Connect us at https://www.wizpanda.com/

--

--

Shashank Agrawal
WizPanda

Serial Entrepreneur | Founder / CTO @ Cooee® — AI-driven Personalised Notifications platform for Better Customer Engagement. bit.ly/shashanka