Jacoco-不排除文件
Jacoco-Not excluding files
我正在使用 Gradle 和 Jacoco。这是我的 build.gradle
:
jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'**/TrackingDataRecord.java'
])
})
}
}
test.finalizedBy(project.tasks.jacocoTestReport)
我试图排除那个 java 文件,但它仍然显示 SonarQube 上的覆盖范围。这是为什么?
Gradle 任务 jacocoTestReport
通过分析 JaCoCo exec
文件和 Java class
文件生成 XML/HTML/CSV 报告。
SonarQube 不使用 Gradle 任务 jacocoTestReport
生成的报告,而是通过分析 JaCoCo exec
文件和 Java [=13] 生成自己的报告=] 文件 - 作为 https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project 的证明引用:
| Property | Example | Description
| sonar.jacoco.reportPaths | target/jacoco.exec | Import JaCoCo code coverage reports. Set the property to the path of the JaCoCo .exec
这可能会在未来发生变化,SonarQube 可能会开始导入 XML 报告 - 请参阅 https://jira.sonarsource.com/browse/MMF-1362
关于 SonarQube 中的排除,请参阅 https://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus :
Ignore Code Coverage
You can prevent some files from being taken into account for code coverage by unit tests.
To do so, go to Administration > General Settings > Analysis Scope > Code Coverage and set the Coverage Exclusions property.
我正在使用 Gradle 和 Jacoco。这是我的 build.gradle
:
jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'**/TrackingDataRecord.java'
])
})
}
}
test.finalizedBy(project.tasks.jacocoTestReport)
我试图排除那个 java 文件,但它仍然显示 SonarQube 上的覆盖范围。这是为什么?
Gradle 任务 jacocoTestReport
通过分析 JaCoCo exec
文件和 Java class
文件生成 XML/HTML/CSV 报告。
SonarQube 不使用 Gradle 任务 jacocoTestReport
生成的报告,而是通过分析 JaCoCo exec
文件和 Java [=13] 生成自己的报告=] 文件 - 作为 https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project 的证明引用:
| Property | Example | Description | sonar.jacoco.reportPaths | target/jacoco.exec | Import JaCoCo code coverage reports. Set the property to the path of the JaCoCo .exec
这可能会在未来发生变化,SonarQube 可能会开始导入 XML 报告 - 请参阅 https://jira.sonarsource.com/browse/MMF-1362
关于 SonarQube 中的排除,请参阅 https://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus :
Ignore Code Coverage
You can prevent some files from being taken into account for code coverage by unit tests.
To do so, go to Administration > General Settings > Analysis Scope > Code Coverage and set the Coverage Exclusions property.