Can I develop a Gradle plugin as sibling project in multi project build setup?

(Christopher Molozian) #1

I’m currently developing a plugin to use with my webapp project. They are both sibling projects within a multi project build setup. I’d like to configure the webapp build script to use the plugin. I’m not sure how to do this. Currently I’ve got:

webapp project: build.gradle

buildscript {
    dependencies {
        classpath project(":myplugin")
  apply plugin: "myplugin"

This causes problems with the clean task (it says “ could not remove myplugin build folder”) and the plugin is not always detected on the buildscript classpath. Essentially what I’d like to do is this:

  • Develop a gradle plugin for use in a sibling project.

  • Test the plugin with the sibling project by making sure that the plugin is built and added to the buildscript classpath

(Luke Daley) #2

Hi Chris,

You can’t develop a plugin as part of your project and use it in the build of your project currently. It’s a bit of a “chicken and egg” problem.

What you can do is move your plugin into the buildSrc directory, which is for this purpose.

(Luke Daley) #3

I should mention that we intend one day to make this possible (using projects from the actual build as build logic instead of requiring use of buildSrc), but there are no immediate plans to work on it.

(Christopher Molozian) #4

Hi Luke,

That was an extremely fast response :wink:

I’d seen the documentation on using buildSrc but had hoped to keep the codebases as decoupled as possible. I thought a multi project build setup might do the trick. Ah well, that’s a shame.

Could I setup the build script in the webapp project to check for the plugin jar and then throw an error if it’s not been built, otherwise include it in the build script classpath? So that I could use it within the build script with

apply plugin: "myplugin"

(Richard Cole) #5

Hi - is this still the best approach to break the ‘chicken-and-egg’ situation of developing plugins? I have a similar issue where I have two subprojects, one is the plugin itself and the other is the test-app that uses my plugin.

(Peter Niederwieser) #6

Alternatively, the test app could have its own build, which gets invoked from the overall build with a ‘GradleBuild’ task.