Is it possible to create a multi-project setup for plugins in the buildSrc directory?

Is it possible to create a multi-project setup for plugins in the buildSrc directory? I’d like to create and use a collection of plugins within a wider project but I’d like to develop each plugin individually. e.g.

root
  |-- project1
  |
    |-- build.gradle
  |-- project2
  |
    |-- build.gradle
  |-- buildSrc
  |
    |-- plugin1
  |
    |
   |-- build.gradle
  |
    |-- plugin2
  |
    |
   |-- build.gradle
  |
    |-- build.gradle
  |-- build.gradle

buildSrc is a separate build. It should be possible to turn it into a multi-project build by putting an appropriate settings.gradle into the buildSrc directory.

Hey Peter,

Thank you for the prompt response, I re-factored my build environment into the format I laid out above and the collection of plugins are successfully built. However, I’m having trouble actually referencing them for use in the parent multi-project setup.

e.g. I’d like to use plugin1 in the project1 build script. When I was using only one plugin in buildSrc this was as simple as:

apply plugin: "plugin1"

Now with the multi-project setup in ‘buildSrc’ I don’t know how to reference a particular plugin in the ‘project1/build.gradle’ script?

The ‘buildSrc’ mechanism works by putting the runtime classpath of the root project in buildSrc. If you have all your plugins arranged as child projects, add this to the bottom of the build.gradle in ‘buildSrc/’

apply plugin: "java"
dependencies {
   runtime subprojects.findAll { it.getTasksByName("jar", false) }
 }

The solution works very well until I add dependencies to a plugin and try to use it in one of the child projects e.g. ‘buildSrc/plugin1/build.gradle’

dependencies {
    compile group: "com.madgag", name: "org.eclipse.jgit", version: "0.10.99.0"
}

and add the plugin in to a child project e.g. ‘root/project1/build.gradle’

apply plugin: "plugin1"

I get the following error:

Could not find group:com.madgag, module:org.eclipse.jgit, version:0.10.99.0.
Required by:
    :buildSrc:unspecified > buildSrc:plugin1:0.0.1

Ok, once I understood exactly what Luke’s suggestion does it all made more sense and I was able to solve the issue I mentioned just above.

Using this snippet:

apply plugin: "java"
dependencies {
   runtime subprojects.findAll { it.getTasksByName("jar", false) }
// OR (functionally equivalent)
//
runtime subprojects.collect { project(it.path) }
}

in the main ‘buildSrc/build.gradle’ script makes all the child projects part of it’s dependencies which in turn are included when it is included during the initialization of the root project’s build classpath.

The problem I had occurred when I added dependencies to one of the child plugins. This is because the ‘buildSrc/build.gradle’ did not have a repository definition that could be used to locate the dependencies of the child plugins.

Adding this line to ‘buildSrc/build.gradle’ solved the problem:

repositories {
    mavenCentral()
}

This topic is completely solved for me (although it may be nice to have something in the Gradle documentation to explain how to use buildSrc as a multi-project setup).

I’ve added some docs, they’ll be in the next release. Cheers.