Applying Plugins with External Dependencies to Projects in init.gradle


(npace) #1

Hello,

We have a multi-project Gradle build, that we are building in Jenkins. We also are using Clover and the Gradle-Clover plugin https://github.com/bmuschko/gradle-clover-plugin

The issue, is that we don’t want to have the clover configuration in the build.gradle. So we are pulling the clover gradle portion and license file from a different SVN project and appending it to the project’s build.gradle when Jenkins goes to build it. This was working fine, but then we wanted to go to a multi-project configuration and it broke.

So now, we are trying to get the clover plugin configuration applied to all projects in the build. Simply putting the config in an allprojects closure did not help, because it overwrites the previous one:

allprojects {
    apply plugin 'java'
    //Project's build configuratino
}
  # Appended from clover build file by jenkins
allprojects {
    apply plugin 'clover'
      //Just clover stuff etc.
   //Overwrites other allprojects and removes the java plugin
}

I tried something like :

allprojects << {
  // appended stuff
}

But that doesnt work. So I thought about putting it into a init.gradle file, but this has different issues:

allprojects {
    apply plugin: 'clover'
          buildscript {
        repositories = {
            maven { url 'our artifactory' }
        }
              dependencies { classpath 'bmuschko:gradle-clover-plugin:0.5' }
    }
          dependencies {
        clover 'com.cenqua.clover:clover:3.1.2'
    }
          clover {
        report {
            html = true
        }
    }
}

This does not work either as it seems to be applying the plugin before looking at the buildscript dependencies.

* What went wrong:
Failed to notify action.
> Plugin with id 'clover' not found.

So my question is:

Does anyone know how to apply an external plugin from an init script? Or, have any better suggestion on how to accomplish our goal?

Thanks.


(Luke Daley) #2

I’m not quite understanding what’s happening.

allprojects {
    apply plugin 'java'
    //Project's build configuratino
}
# Appended from clover build file by jenkins
allprojects {
    apply plugin 'clover'
    //Just clover stuff etc.
   //Overwrites other allprojects and removes the java plugin
}

Your syntax is wrong there. It should be:

apply plugin: 'java'

But I’ll assume that’s a copy/paste error.

Any ‘allprojects {}’ blocks are additive and don’t overwrite each other. I think something else is going on here. It would be worth working out exactly what. How are you coming to the conclusion that this is overwriting the previous block?


(npace) #3

Hi Luke,

I’m not sure I see what is wrong with the syntax. Are you saying it’s wrong because the ‘apply plugin ‘java’’ is inside the ‘allprojects {}’ block? This by itself works:

allprojects {
    apply plugin 'java'
    //Project's build configuratino
}

Anyhow, I came to conclusion that the second block is overwriting the previous block because the compileJava tasks disappear.


(Luke Daley) #4

Sorry, made the same mistake in mine. I just updated the above post. You’re missing a necessary colon.

I’m surprised you don’t get a compile exception to be honest.


(npace) #5

Ah I see the issue now. Yeah that was just a typo, I didn’t copy the script I just retyped it in the comment box.


(Luke Daley) #6

I can’t really say what’s going on based on the information you’ve given. Are you sure that whatever Jenkins is doing is not completely overwriting the file?


(npace) #7

Hi Luke, I’m completely sure, as I simplified the test case to a single ‘build.gradle’ in my local Eclipse.

However, I did not keep that test case as I erroneously accepted that multiple ‘allproject {}’ blocks were not allowed. Upon trying to recreate the test case, I can’t get it to happen now, and too many things have changed (we are using gradle wrapper now, etc)

So for now, we will just have to call this unreproducible. We’ll try to retrofit our build scripts to the way we want them with the appended ‘allprojects {}’, and see if this issue arises again.

Thanks for your help.


(Luke Daley) #8

No problems. If you can reproduce in the future, please raise a new topic with a link to this one.