Search code examples
mavengroovygradleandroid-gradle-pluginbuild-script

How to apply Cobertura plugin to all projects or all subprojects


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'
}

Solution

  • 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'  
    }