Multiple versions of custom plugin in buildscript dependencies of multi-project build


(suvelee sarpotdar) #1

Hello,

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?

Appreciate any help or pointers.

Thanks,
Suvelee


(uklance) #2

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.


(suvelee sarpotdar) #3

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?


(uklance) #4

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)


(suvelee sarpotdar) #5

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

Root build.gradle

def rhel7Components = ["daemon-a","daemon-b"]
 
task clean << { delete distDir }
 
allprojects {
                apply plugin: 'idea'
               
                repositories {
                                mavenCentral()
                                mavenLocal()
                                maven { url cmRepo }
                }
               
}
 
 
configure(subprojects.findAll {!rhel7Components.contains(it.name) }) {
                // dependencies for plugins and repositories used by gradle
                buildscript {
                                repositories {
                                                mavenCentral()
                                                mavenLocal()
                                                maven { url myRepo }
                                }
                                dependencies {
                                                classpath 'org.redline-rpm:redline:1.1.10'
                                                classpath 'com.netflix.nebula:gradle-ospackage-plugin:1.9.2'
                                                classpath 'com.google.collections:google-collections:1.0'
                                                classpath 'com:ssarpotdar:myPlugin:1.0'
                                }
                }
               
                configurations {
                                packageFiles
                }
               
                dependencies {
                                packageFiles 'com:ssarpotdar:myFiles:1.3@zip'
                }              
}
 
 
configure(subprojects.findAll {rhel7Components.contains(it.name)}) {               
                // dependencies for plugins and repositories used by gradle
                buildscript {
                                repositories {
                                                mavenCentral()
                                                mavenLocal()
                                                maven { url myRepo }
                                }
                                dependencies {
                                                classpath 'org.redline-rpm:redline:1.1.10'
                                                classpath 'com.netflix.nebula:gradle-ospackage-plugin:1.9.2'
                                                classpath 'com.google.collections:google-collections:1.0'
                                                classpath 'com:ssarpotdar:myPlugin:2.4'
                                }
                }
               
                configurations {
                                packageFiles
                }
               
                dependencies {
                                packageFiles 'com:ssarpotdar:myFiles:2.4@zip'
                }
}

daemon-a project’s build.gradle

apply plugin: 'rhel-myplugin'

daemon-b project’s build.gradle

apply plugin: 'rhel-myplugin'

daemon-c project’s build.gradle

apply plugin: 'rhel-myplugin'

(uklance) #6

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.


(suvelee sarpotdar) #7

I tried putting build script block in each project and that seems to work fine. Thanks a lot for all your help.