Apply gradle custom jar plugin

I created a simple groovy plugin for gradle.

in my gradle.build file, I have the following:

apply plugin: 'groovy' dependencies { compile gradleApi() compile localGroovy() } 

Everything works fine, I get the assembly directory, and .jar is generated in the lib folder, I think this is a standalone plugin.

Now I want to know how to register this new plugin in my gradle installation, so I can do the plugin application: 'myPlugin' I did the following:

  • Threw the plugin into the plugin folder during installation
  • Created the myplugin.properties file and included it in the META-INF folder
  • put the same properties file in META-INF in src dir (desperation action)

Well, after each step, when I try to apply the plugin, I get an error:

  • Plugin with id 'myplugin' not found

How can I get it right?

can you provide a list of steps that will make my plugin work? (Im new for gradle + groovy)

thanks for the help

+9
source share
2 answers

Chapter 58 of the user manual contains all the necessary information. Eventually:

  • Put your myPlugin.properties in the structure of your project, in src / main / resources / META-INF / gradle-plugins /
  • Build your jar as you usually do
  • In the script you want to use this plugin, add a buildscript closure to something like:

     buildscript { repositories { flatDir dirs: "build/libs" } dependencies { classpath "your.group:your-plugin:1.0.0" } } 

Or you will wish any settings for repositories and dependencies , but you need to use the classpath configuration as I did here. I don’t think you can (or should!) Add the jar to the Gradle plugin directory, as you did.

Note: flatDir does not allow transitive dependencies. The same rule for dependency management applies to buildscript, so you can use the regular maven or ivy repository to deploy your plugin.

+10
source

View samples/customPlugin and samples/customDistribution in a full Gradle schedule (or on GitHub ). They must have all the necessary information.

+2
source

All Articles