gradle - 如何在 Gradle 中为多模块项目聚合 Sonar 报告?

标签 gradle sonarqube jacoco sonar-runner gradle-plugin

我有一个多模块 Gradle 4.6 项目和 Sonarqube 7。Sonarqube 和 Jacoco 配置如下:

apply plugin: 'org.sonarqube'

sonarqube {
    properties {
        property 'sonar.host.url', sonarHostUrl
        property 'sonar.jacoco.reportPaths', "$buildDir/reports/jacoco"
    }
}

apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.7.9"
}

jacocoTestReport {
    group = "Reporting"
    reports {
        xml.enabled true
        xml.destination "${buildDir}/reports/jacoco/report.xml"
        csv.enabled false
        html.enabled true
    }
}

test {
    jacoco {
        append = true
    }
}

我正在使用以下命令运行构建和 Sonar :
./gradlew clean build jacocoTestReport --info

./gradlew sonarqube -Dsonar.branch=nonMasterBranch --info

我希望它能够汇总 Sonar 报告并向我展示 Sonarqube 中的单个项目(我在 jacoco 配置中使用 append=true)。但是,我每个模块都有一个非常困惑的项目。

非常感谢您的任何想法!我已经为这个 hell 任务工作了太多时间并且没有任何想法:C

最佳答案

根据this answer , 你应该试试 Jacoco Coverage Gradle Plugin

只需将其添加到您的根项目中:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.palantir:jacoco-coverage:0.4.0'      
    }
}

apply plugin: 'com.palantir.jacoco-full-report'

根据文档:

The com.palantir.jacoco-full-report plugin adds a task that produces a Jacoco report for the combined code coverage of the tests of all subprojects of the current project.

关于gradle - 如何在 Gradle 中为多模块项目聚合 Sonar 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49575949/

相关文章:

c# - SonarQube 不会分析名为 Test* 的 C# 项目

java - 如何告诉 Sonar 有关托管无限循环的信息

java - 有没有办法获得 PowerMockito 类的 Jacoco 代码覆盖率?

android - Android gradle插件如何选择所有设备?

android - 每当我在公司的应用程序上工作时,都需要更新Kotlin吗?

android - 重新安装Android Studio后无法在设备模拟器上运行应用

testing - Gradle-Jacoco-JMockit-测试正在挂起而未进行

java - 尝试从 Jhipster 项目获取 war 文件

java - SonarQube 看不到方法引用

java - 添加在 @PrepareForTest 中编写 Junit 的类可以使 Sonar 覆盖率为零