Java 运行 jacocoReport
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20032366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running jacocoReport
提问by Pavel Bernshtam
I'm using Gradle 1.7 and Jacoco plugin. My project uses Java and Scala plugins.
When I run gradlew -i clean jacocoTestReport
我正在使用 Gradle 1.7 和 Jacoco 插件。我的项目使用 Java 和 Scala 插件。
当我跑gradlew -i clean jacocoTestReport
Report is not created and I see in the log
报告未创建,我在日志中看到
:bl:jacocoTestReport (Thread[Daemon Thread 13,5,main] - start
:bl:jacocoTestReport
Skipping task ':bl:jacocoTestReport' as task onlyIf is false.
:bl:jacocoTestReport SKIPPED
:bl:jacocoTestReport (Thread[Daemon Thread 13,5,main]) - complete
What does it mean? Why report is not created?
这是什么意思?为什么没有创建报告?
采纳答案by Peter Niederwieser
The task will only run if coverage data is available. You can make sure of that by also running the test
task.
只有在覆盖数据可用时,该任务才会运行。您还可以通过运行test
任务来确保这一点。
回答by Pedro José Piquero Plaza
Add the following at a top level to your build.gradle:
在 build.gradle 的顶层添加以下内容:
test {
finalizedBy jacocoTestReport
}
This means that at the end of the test task the jacocoTestReport task should be run. You will receive your coverage analysis after run the tests.
这意味着在测试任务结束时应该运行 jacocoTestReport 任务。运行测试后,您将收到覆盖率分析。
回答by StylusEater
None of the above worked for me. What worked for me was the following
以上都不适合我。对我有用的是以下内容
Add to the top of my build.gradle:
添加到我的 build.gradle 的顶部:
apply plugin: 'jacoco' // code coverage reports
Add the following as a 'task':
将以下内容添加为“任务”:
// Generate code coverage reports ... run with jacoco
jacocoTestReport{
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/reports/jacoco/html"
}
executionData = files('build/jacoco/test.exec')
}
Add the following to your gradle test task:
将以下内容添加到您的 gradle 测试任务中:
finalizedBy jacocoTestReport
Then I issued the following command:
然后我发出了以下命令:
gradle run test jacoco