Jacoco离线仪器Gradle脚本

我试图寻找Jacoco离线仪器gradle脚本片段,但找不到。 是否可以通过gradle脚本进行Jacoco离线检测? 如果是的话…它的一个例子就是伟大的。 谢谢。

以下是使用JaCoCo Ant任务执行脱机检测的Gradle脚本示例:

apply plugin: 'java' configurations { jacoco jacocoRuntime } dependencies { jacoco group: 'org.jacoco', name: 'org.jacoco.ant', version: '0.7.9', classifier: 'nodeps' jacocoRuntime group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.7.9', classifier: 'runtime' testCompile 'junit:junit:4.12' } repositories { mavenCentral() } task instrument(dependsOn: ['classes']) { ext.outputDir = buildDir.path + '/classes-instrumented' doLast { ant.taskdef(name: 'instrument', classname: 'org.jacoco.ant.InstrumentTask', classpath: configurations.jacoco.asPath) ant.instrument(destdir: outputDir) { fileset(dir: sourceSets.main.output.classesDir) } } } gradle.taskGraph.whenReady { graph -> if (graph.hasTask(instrument)) { tasks.withType(Test) { doFirst { systemProperty 'jacoco-agent.destfile', buildDir.path + '/jacoco/tests.exec' classpath = files(instrument.outputDir) + classpath + configurations.jacocoRuntime } } } } task report(dependsOn: ['instrument', 'test']) { doLast { ant.taskdef(name: 'report', classname: 'org.jacoco.ant.ReportTask', classpath: configurations.jacoco.asPath) ant.report() { executiondata { ant.file(file: buildDir.path + '/jacoco/tests.exec') } structure(name: 'Example') { classfiles { fileset(dir: sourceSets.main.output.classesDir) } sourcefiles { fileset(dir: 'src/main/java') } } html(destdir: buildDir.path + '/reports/jacoco') } } } 

gradle jacoco插件不支持离线检测,它总是通过java代理进行在线检测。

如果ant jacoco插件支持脱机检测,这可能是让离线检测工作在gradle中的最佳方法