10

I've created a simple groovy-based plugin for gradle.

in my gradle.build file I have the following:

apply plugin: 'groovy'

dependencies {
    compile gradleApi()
    compile localGroovy()
}

Everything works great, I get a build directory and a .jar is generated in the lib folder, I guess this is the standalone plugin.

Now I want to know how to register this new plugin into my gradle instalation, so I can do apply plugin: 'myPlugin' I've done the following:

  • Droped the plugin into the plugin folder in the installation
  • Created the myplugin.properties file and included it in the META-INF folder
  • placed the same properties file in the META-INF in the src dir (act of desperation)

Well after every step when I try to apply the plugin I get the error:

  • Plugin with id 'myplugin' not found

How can I get this right??

can you state a list of steps that will get my plugin working? (Im new to gradle+groovy)

Thanks for the help

RicardoE
  • 1,665
  • 6
  • 24
  • 42

2 Answers2

11

The chapter 58 of the user guide has all the information you need. In summary:

  • Put your myPlugin.properties inside your project structure, in src/main/resources/META-INF /gradle-plugins/
  • Build your jar like you usually do
  • In the script you wish 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 whatever settings for repositories and dependencies you wish, but you need to use the classpath configuration as I've done here. I don't think you can (or should!) add the jar to the plugin dir of Gradle like you did.

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

Pascal Gélinas
  • 2,744
  • 19
  • 20
  • I've tried this, and still got the following error: Could not resolve all dependencies for configuration ':classpath'. > Could not find org.gradle.mypluginpack:MyPlugin:1.0-SNAPSHOT. Required by: :test:unspecified – RicardoE May 09 '13 at 20:25
  • 1
    Well, probably the repository you specified didn't contain your plugin's jar. My `flatDir` was just for the sake of example. The same rule for dependency management applies in the `buildscript` closure. – Pascal Gélinas May 10 '13 at 12:31
  • It seems to me that this wouldn't work because it wouldn't include dependencies of that plugin – Vic Seedoubleyew Apr 15 '19 at 00:46
  • @VicSeedoubleyew The question didn't mention any dependencies of the plugin and I did mention in the previous comment that dependency management applies in the buildscript; flatDir is for the sake of example and wouldn't resolve any dependencies, but you can still use a custom maven/ivy repository to resolve transitive dependencies. I'll update the answer to clarify. – Pascal Gélinas Jun 03 '19 at 15:35
1

Check out the samples/customPlugin and samples/customDistribution samples in the full Gradle distribution (or on GitHub). They should have all information that you need.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259