我正在 IntelliJ Java IDE 中运行 Gradle 构建。这SonarQube 跑步者 http://www.gradle.org/docs/current/userguide/sonar_runner_plugin.htmlGradle 插件与JaCoCo http://www.gradle.org/docs/current/userguide/jacoco_plugin.html摇篮插件。
Problem:我收到消息No information about coverage per test.
, (not的副本这个帖子 https://stackoverflow.com/questions/16615558/no-information-about-coverage-per-test-from-sonar-with-jacoco-ant-build,见下文)并且覆盖率显示在 SonarQube 中,但仅作为总体百分比,而不是每个文件的详细报告:
难道我做错了什么?也许是 SonarQube 中的一个错误(因为它是与科贝尔图拉 https://jira.codehaus.org/browse/SONARPLUGINS-3711最近)?
这是我的 build.gradle:
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'sonar-runner'
sourceCompatibility = 1.7
project.version = '1.0'
project.group = 'com.acme.sandbox'
project.description = 'just a test project'
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
// JaCoCo test coverage configuration
tasks.withType(Test) { task ->
jacoco {
append = false
}
}
// Sonar configuration
sonarRunner {
sonarProperties {
property 'sonar.host.url', 'http://host:port'
property 'sonar.jdbc.url', 'myJdbcURL'
property 'sonar.jdbc.username', 'dbuser'
property 'sonar.jdbc.password', 'dbpass'
property 'sonar.login', 'builduser'
property 'sonar.password', 'buildpass'
property 'sonar.profile', 'profilename'
property 'sonar.branch', 'DEV'
property 'sonar.language', 'java'
property 'sonar.sourceEncoding', 'UTF-8'
property 'sonar.verbose', 'true'
//property 'sonar.tests', "$projectDir\\src\\test\\java"
//property 'sonar.binaries', "${buildDir}\\classes\\main,${buildDir}\\classes\\test"
//property 'sonar.java.coveragePlugin', 'jacoco'
property 'sonar.jacoco.reportPath', "${buildDir}\\jacoco\\test.exec"
property 'sonar.junit.reportsPath', "${buildDir}\\test-results"
}
}
现在如果你执行clean
, 其次是sonarRunner
, 一个雅可可测试执行程序文件被创建并处理:
<snip>
18:35:27.705 DEBUG - Initializers :
18:35:27.706 INFO - Base dir: D:\path\to\JaCoCoTest
18:35:27.706 INFO - Working dir: D:\path\to\JaCoCoTest\build\sonar
18:35:27.707 INFO - Source dirs: D:\path\to\JaCoCoTest\src\main\java
18:35:27.708 INFO - Test dirs: D:\path\to\JaCoCoTest\src\test\java
18:35:27.708 INFO - Binary dirs: D:\path\to\JaCoCoTest\build\classes\main
<snip>
18:35:27.931 INFO - JaCoCo IT report not found.
18:35:27.933 INFO - JaCoCo reports not found.
18:35:27.938 DEBUG - Sensors : JavaSquidSensor -> QProfileSensor -> FindbugsSensor -> CpdSensor -> PmdSensor -> SurefireSensor -> CheckstyleSensor -> InitialOpenIssuesSensor -> ProfileEventsSensor -> ProjectLinksSensor -> VersionEventsSensor -> FileHashSensor -> JaCoCoSensor
<snip>
18:35:34.055 INFO - Sensor SurefireSensor...
18:35:34.056 INFO - parsing D:\path\to\JaCoCoTest\build\test-results
18:35:34.116 INFO - Sensor SurefireSensor done: 61 ms
<snip>
18:35:34.936 INFO - Sensor JaCoCoSensor...
18:35:34.939 INFO - Analysing D:\path\to\JaCoCoTest\build\jacoco\test.exec
18:35:35.027 INFO - No information about coverage per test.
18:35:35.028 INFO - Sensor JaCoCoSensor done: 92 ms
这个帖子 https://stackoverflow.com/questions/16615558/no-information-about-coverage-per-test-from-sonar-with-jacoco-ant-build建议设置sonar.tests
,我已经尝试过但没有效果。日志文件显示检测到测试源和二进制文件位于正确的位置。
FWIW,我在 Maven 构建中使用了相同的设置,并且它有效。但这里不能使用 Maven。
版本号:
- 声纳Qube 4.3
- SonarQube Java 生态系统 2.2.1
- Gradle 1.12(也:1.11)
- IntelliJ IDEA 旗舰版 13.1.3
- Java 1.7
这里是完整的测试项目 http://53327882.de.strato-hosting.eu/posted/so/JaCoCoTest.zip供下载,以及full log http://53327882.de.strato-hosting.eu/posted/so/JaCoCoTest-SonarRunner.log.