Creating a Standalone Custom Gradle Plugin

In this post we are going to create a standalone custom gradle plugin which can be used as shareable JAR. 

Prerequisites :

  • Gradle > 2.3 or latest
  • Groovy or Java installed
  • Intellij or any other IDE

 

Here I’m going to use Intellij IDE, Groovy 2.4.7 and Gradle 3.1

So let’s start building our standalone custom gradle plugin step by step :

  • Create a new project from Intellij IDE, File -> New -> Project : Gradle

Add Groovy, Java or both as additional libraries

  •  GroupId – com.custom.plugin, ArtifactId – myplugin, Version – 0.0.1 – RC1
  • Till now configuration will give you project structure like :

              

 

  • Next just create new package like com.custom for instance here just to add our classes:

              src -> main -> groovy -> com.custom

  • Now our build.gradle should look like:

  • Create new task class here as MyTask.groovy

  • Create another groovy class MyPlugin to register our custom created task:

              

 

  • Now, since we are ready with the basic implementation of creating and registering our custom task, our next step is to register our implementation class in <Plugin_Name>.properties file, inside following structure:

              

             

               and inside the file we need to add given line:

                implementation-class=com.custom.MyPlugin

  • Now, we need to publish our plugin in some local or maven repo. Here I’m just publishing it to a local repo using command: ./gradlew uploadArchives
  • We just need to add following lines in the build script file of the consumer project

              

 

About CauseCode: We are a technology company specializing in Healthtech related Web and Mobile application development. We collaborate with passionate companies looking to change health and wellness tech for good. If you are a startup, enterprise or generally interested in digital health, we would love to hear from you! Let's connect at bootstrap@causecode.com

Leave a Reply

Your email address will not be published. Required fields are marked *

STAY UPDATED!

Do you want to get articles like these in your inbox?

Email *

Interested groups *
Healthtech
Business
Technical articles

Archives