The ‘plugin’ project contains the custom plugin, and in the two example projects I want to use that ‘plugin’.
In the build.gradle files of the examples I tried
apply plugin: 'myplugin'
and
apply plugin: com.plugin.MyPlugin
But none worked.
I also tried adding the project(‘plugin’) to the example dependencies in ‘compile’ and ‘classpath’ configurations. ‘classpath’ failed because it doesn’t exist as configuration, and ‘compile’ will just fail saying it can’t find ‘myplugin’.
A plugin cannot be used from the same build that builds it. What you can do is to use ‘GradleBuild’ tasks to kick off one or more nested builds for the examples. The example builds can then pull in the plugin using a ‘buildscript’ block and apply it.
hmm… interesting. And the example builds pulling in the plugin using a buildscript block, can that be done directly (file/project based?) or does that need to go via a maven/ivy/… dependency?
If the plugin has external dependencies, it’s probably best to have the main build publish to a ‘file:///’ based maven/ivy repo, and have the example builds pull from there. Otherwise, plain file dependencies should be good enough (see regular dependency management).
I did not get it to work the way I wanted. Instead I went with just having the examples as separate projects not bound to the plugin project, and have the examples depend on the jcenter dependency instead