版本信息
sonarqube:Version 8.2
jacoco: 0.8.5
sonar: 3.0
配置
根目录下build.gradle
plugins {
id 'jacoco'
}
subprojects {
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.5"
}
//Configuring test task
jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.enabled true
//html.destination file("${buildDir}/jacocoHtml")
}
}
sonarqube {
apply plugin: 'java-library'
apply plugin: 'org.sonarqube'
properties {
property "java-module.sonar.sources", "src/main"
property "sonar.java.binaries", "${buildDir}/classes"
property "sonar.sourceEncoding", "UTF-8"
property "java-module.sonar.tests", "src/test"
property "sonar.log.level", "INFO"
// property "sonar.jacoco.reportPaths", allTestCoverageFile
property "sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
}
test.finalizedBy(jacocoTestReport)
}
sonarqube {
properties {
property "sonar.verbose", "true"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.modules", "java-module"
property "sonar.projectKey", "integration-*"
property "sonar.projectName", "Integration*"
property "sonar.coverage.jacoco.xmlReportPaths", "${rootDir}/build/reports/jacoco/test/jacocoTestReport.xml"
}
}
tasks['sonarqube'].dependsOn(jacocoTestReport)
执行测试
./gradlew test -x api-test:test jacocoTestReport
./gradlew -x clean -x test sonarqube -Dsonar.host.url=$SONAR_HOST -Dsonar.login=$SONAR_LOGIN -Dsonar.pullrequest.branch=$CI_COMMIT_REF_NAME
网友评论