Gradle tip: Using gradle plugin from local maven repository

Today, I was trying to use a Gradle plugin that was currently not published to Bintray or any other public repository. I performed following actions to use that plugin in my project.

Step 1: Build the gradle plugin

Clone the gradle plugin to your local machine and run the following command to publish plugin to your local Maven repository.

$ ./gradlew clean build
$ ./gradlew publishToMavenLocal

Step 2: Add plugin to your project build.gradle

Once you have published your plugin to local Maven repository then you need to add the plugin to your project so that you can execute it. Add the following to your build.gradle.

apply plugin: 'my-demo-plugin'

buildscript{
  repositories {
      mavenLocal()

      dependencies{
        classpath 'io.shekhar.gradle.plugins:my-demo-plugin:0.1-SNAPSHOT'
      }
  }
}

In the build.gradle shown above we are applying our plugin my-demo-plugin using the apply plugin command. Then we used buildscript method to add our plugin to classpath. Also, we used local maven repo using mavenLocal() Gradle function.