如何将Cobertura插件应用于所有项目或所有子项目

时间:2015-03-24 17:38:38

标签: maven groovy gradle android-gradle build-script

我试图将Cobertura插件应用于我的Gradle构建脚本中的所有项目和子项目。但是,应用于所有脚本时,脚本无法找到该插件。这就是我所拥有的:

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

2 个答案:

答案 0 :(得分:1)

这就是build.gradle的样子:

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

allprojects {
    apply plugin: 'net.saliman.cobertura'  
}

答案 1 :(得分:1)

您可能还会发现,您希望将所有子项目cobertura报告合并到整个项目的一个漂亮的顶级报告中。

要做到这一点,你需要cobertura gradle插件2.2+我相信,配置就像:

// 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)

来自syncsynchalt对这个问题的好评: https://github.com/stevesaliman/gradle-cobertura-plugin/issues/10