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.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

%d bloggers like this: