Cannot apply custom plugin

Trying to write a custom plugin and apply it. Followed guides on

My project layout is exactly as described in the second link above. However, no matter what I do, I get a “plugin not found” error. The tests I’ve copied and adapted from second link above pass successfully. So I’ve tried loading the plugin

  • locally via flatDir
  • locally via files()
  • locally via mavenLocal()
  • remotely via our maven-style repository

Based on the various error messages I’ve observed while debugging this issue, I’m pretty sure the problem is not in gradle not being able to find/download the JAR which contains the plugin but about something in the plugin’s configuration/layout which makes gradle cough on it.


plugin_project

  • rootProject.name = ‘some-thing’

  • src/main/resources/META-INF/gradle-plugins/foo.bar.some-thing.plugin.properties exists

    group = 'foo.bar’
    version = ‘0.0.1-SNAPSHOT’


consumer_project

buildscript {
        flatDir {
            dirs 'libs'
        }
    }
    dependencies {
        classpath group: 'foo.bar', name: 'some-thing', version: '0.0.1-SNAPSHOT'
    }
}
// none of these work, always result in "plugin not found"
apply plugin: 'foo.bar.some-thing'
//apply plugin: 'foo.bar.some-thing.plugin'
//apply plugin: 'some-thing'
//apply plugin: 'some-thing.plugin'

Any suggestion what I can look for ? I’m at a total loss on how to proceed, cannot find anything on the web which I have not already tried already.

Thanks & Regards

I’m not 100% sure, but you’ve probably published a jar into your local .m2 repository that doesn’t have the appropriate plugin properties file in the jar.

If you run gradle buildEnvironment (without applying your plugin), do you see your plugin listed as a dependency? If so, you’re adding the dependency correctly and there’s something wrong with the jar Gradle is trying to use.

I wouldn’t try to use mavenLocal() to try out your new plugin. TestKit tests are best at capturing/describing the behavior you want your plugin to have, but for something quick and dirty to try things out, I would suggest to use a composite build. This will make sure you’re using the latest and greatest version of your plugin without going through a manual publishing step.

You would keep what you have in your buildscript {} block and apply the plugin as foo.bar.some-thing.plugin. When you want to try your plugin after making changes to it, you would use:

gradle tasks --include-build path/to/plugin_project

There are some more focused Plugin development guides at https://guides.gradle.org that might provide you more clues.

If the buildEnvironment task suggested by @sterling shows the dependency, try applying the plugin using the class directly.

For example, if the plugin class is com.test.plugins.MyPlugin, then try apply plugin: com.test.plugins.MyPlugin.

What is in the src/main/resources/META-INF/gradle-plugins/foo.bar.some-thing.plugin.properties file? Also, based on that filename, you want apply plugin: 'foo.bar.some-thing.plugin'.

gradle buildEnvironment does show the dependency and all of its inherited dependencies as well, both for the local file resolution and the remote repository. So I removed all local “manual” resolutions, reverted everything back to using our repository and skipped the suggested composite builds step (though it’s still good to know about it for the future).

Adding apply plugin: foo.bar.name1.name2.plugin.PluginClass (without enclosing single quotes) results in Could not get unknown property 'foo' for root project.

In the end, it seems to have been a typo in a name/path somewhere, though I’m dead sure I had already tried every possible combination at least twice. However, it’s now working without issues.

Thanks for the help and sorry for the waste of time.

Edit: I can mark only one answer as the solution :confused: