1

I'm trying to apply the Cobertura plugin to all projects and subprojects in my Gradle build scripts. However, the scripts are unable to find the plugin when applied to all. Here is what I've got:

buildscript {
    repositories {
        jcenter()
    }
}

allprojects {
    beforeEvaluate {
        project.buildscript {
            repositories {
                jcenter()
            }

            dependencies {
                classpath 'net.saliman:gradle-cobertura-plugin:2.2.7'
            }
        }
    }
}

subprojects {
    apply plugin: 'net.saliman.cobertura'
}
jjNford
  • 5,170
  • 7
  • 40
  • 64

2 Answers2

2

This is how build.gradle should look like:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'net.saliman:gradle-cobertura-plugin:2.2.7'
    }
}

allprojects {
    apply plugin: 'net.saliman.cobertura'  
}
Opal
  • 81,889
  • 28
  • 189
  • 210
2

You may also find that you want to merge all your subprojects cobertura reports into one beautiful top level report for the entire project.

To do this you will need cobertura gradle plugin 2.2+ I believe and the configuration for that is something like:

// note - all non-cobertura config is stripped out of this example
allprojects {
    apply plugin: 'cobertura'
}
subprojects {
    cobertura {
        coverageIgnoreTrivial = true
    }
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "net.saliman:gradle-cobertura-plugin:2.2.2"
    }
}
def files = subprojects.collect { new File(it.projectDir, '/build/cobertura/cobertura.ser') }
cobertura {
    coverageFormats = [ 'xml', 'html' ]
    coverageSourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()
    coverageMergeDatafiles = files
}
test.dependsOn(subprojects.test)

which is from syncsynchalt's great comment on the issue here: https://github.com/stevesaliman/gradle-cobertura-plugin/issues/10

dawogfather
  • 604
  • 5
  • 10