I have a multi-project setup with 5 subprojects that make use of a gradle custom plugin jar with version 1.0. This custom plugin extends the gradle DSL and provides customized script files for daemon processes that run on RHEL6 OS. We are slowly migrating to RHEL7 hence I created version 2.0 of the custom plugin to provide RHEL7 script files.
I would like to apply this 2.0 version to only 2 of the sub-projects. I was able to do that using configure block in root build.gradle. However at runtime, gradle doesn’t recognize the new attribute added in the 2.0 version of the extension and refers to old version of the plugin class.
Is it possible to apply multiple versions of the custom gradle plugin to some of the projects in a multi-project setup? Or should the plugin be enhanced in a way that it is backward compatible and only the latest version is applied in build script dependencies for all the sub-projects?
If the plugin is in buildSrc then it will be on the classpath of all projects.
If the plugin is not in buildSrc (ie dependency from repository or from a composite build) then you should be able to have different plugin versions in different projects within a multi project build.
Thanks for the prompt response. I do have it as jar dependency that is pulled from artifactory. Do you think it might help if I put each project’s build script dependencies in its own build.gradle rather than having configure blocks in root build.gradle?
I haven’t seen any sample code yet so hard to tell exactly what you’re doing. It’s quite possible that one project’s buildscript classpath could “bleed” into another if everything is in the same build.gradle (eg the root project’s classpath “bleeds” into the subprojects)
My bad, I should have posted the sample code here for better understanding. Here is the stripped down version of my code. I am new to this forum so hopefully I have used the correct formatting for copying pasting the code snippet. I would like to mention that I am using older version of gradle (v 1.11). I am hopping to upgrade my gradle version very soon.
settings.gradle
include 'daemon-a', // on rhel7
'daemon-b' // rhel7
'daemon-c' // still on rhel6
I know there’s some weirdness with how the buildscript { ... } block is evaluated. I think there’s a regex or something that gets the buildscript {} block before evaluating anything else.
But you are nesting a buildscript block within other logic. I believe this may create a bit of a chicken or egg problem. The Gradle team can likely shed more light on how the buildscript block is evaluated
I’d definitely try moving the buildscript logic into project specific gradle files.