gradle+sonarqube方式

huaqiangli 2020-02-19

1、配置build.gradle文件的jacoco

apply plugin: ‘jacoco‘

jacoco {
   toolVersion = "0.8.5"
   reportsDir = file("$buildDir/customJacocoReportDir")
}

jacocoTestReport {
    reports {
        xml.enabled true
        csv.enabled false
        xml.destination file("${buildDir}/jacoco.xml")
        html.destination file("${buildDir}/jacocoHtml")
    }
}

2、配置build.gradle文件的sonarqube

apply plugin: "org.sonarqube" version "2.6.1"
sonarqube {
    properties {
        property "sonar.projectName", "FlyCloud"
        property "sonar.projectKey", "FlyCloud"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.projectVersion", "1.0-SNAPSHOT"
        property "sonar.modules", "java-module"
//        property "javascript-module.sonar.language", "js"
        property "java-module.sonar.language", "java"
//        property "sonar.test.exclusions", "**/*"
    }
}

3、在终端执行gradle build命令对程序进行构建。
4、在终端执行gradle sonarqube命令,执行完之后在sonar客户端即可看到代码的覆盖率信息。

相关推荐