gradle jacoco插件不生成exec文件

时间:2018-05-02 07:58:51

标签: gradle jacoco

我已完成从gradle 3.5到gradle 4.6的gradle迁移。迁移后,exec文件已停止生成。 ' /构建'文件夹不包含' jacoco'夹。 如果我运行gradle命令 - debug它写入日志:

  

[org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter]   跳过任务':常见:jacocoTestReport'仅作为任务如果是假的。

以下是gradle脚本的一部分:

subprojects {
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'idea'
...
jacocoTestReport {
    reports {
        xml.enabled true
        csv.enabled false
    }
    afterEvaluate {
        classDirectories = files(classDirectories.files.collect {
            fileTree(dir: it,
                    exclude: ['**/dto/**', '**/endpoint/**','**/enpoints/**', '**/spring/**',
                              '**/servlet/**','**/handler/**', '**/jpa/**', '**/filter/**', '**/events/**', '**/dao/**',
                              '**/exception/**', '**/http/**', '**/jdbc/**', '**/bigquery/**', '**/enums/**',
                              '**/repository/**', '**/combination/**', '**/datastore/**', '**/cassandra/**',
                              '**/google/**', '**/exceptions/**', '**/logging/**', '**/JavaGeneratedContext.java', '**/Q*.java'])
        })
    }
}

test {
    enabled = !skipTests
    allJvmArgs = [
        '-Dfile.encoding=utf-8'
    ]
    useJUnit {
        excludeCategories 'com.severn.common.test.IntegrationTest'
    }
    /*jacoco {
        enabled = true
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
    }*/
    finalizedBy jacocoTestReport
}

...

}

1 个答案:

答案 0 :(得分:0)

确保

1)您的调试信息在编译期间在顶级Gradle文件(allprojects { ... })中启用。有关详细信息,请参阅此处:Jacoco Unit and Integration Tests coverage - individual and overall

   tasks.withType(Compile) {
     options.debug = true
     options.compilerArgs = ["-g"]
   }

2)尝试从test任务中删除整个Jacoco配置(如果在jacocoTestReport任务期望的默认位置生成,请确保放置.exec文件)。确保test任务正在运行(并且不会以某种方式被排除)。出于测试目的(缩小此.exec未获得创建的问题),您可以强制jacocoTestReport任务依赖test任务。

tasks.withType(Test) {enabled = true}

3)有关Java单/多级项目的Jacoco示例,请参阅最新的Gradle 4.6软件包(tar / zip)以获取提示。

PS:默认JaCoCo版本升级为 0.8.0 查看是否在jacoco块内强制使用此版本有帮助。

https://docs.gradle.org/4.6/release-notes.html JaCoCo插件已升级为默认使用JaCoCo版本0.8.0。

相关问题