Jacoco代码覆盖率显示Jenkins覆盖率为0% [英] Jacoco code coverage show 0% coverage on Jenkins

查看:238
本文介绍了Jacoco代码覆盖率显示Jenkins覆盖率为0%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了大多数可用于类似问题的答案,但没有一个适合回答我的问题.

I have read most of the answers available for similar questions but none of those fit to answer my question.

我在pom文件中的个人资料如下:

My profile in pom file looks like this:

            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.7.201606060606</version>
                    <executions>
                        <!-- Prepares the property pointing to the JaCoCo runtime agent which 
                            is passed as VM argument when Maven the Surefire plugin is executed. -->
                        <execution>
                            <id>pre-unit-test</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <!-- Sets the path to the file which contains the execution data. -->
                                <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                                <!-- Sets the name of the property containing the settings for JaCoCo 
                                    runtime agent. -->
                                <propertyName>surefireArgLine</propertyName>
                            </configuration>
                        </execution>
                        <!-- Ensures that the code coverage report for unit tests is created 
                            after unit tests have been run. -->
                        <execution>
                            <id>post-unit-test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <!-- Sets the path to the file which contains the execution data. -->
                                <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                                <!-- Sets the output directory for the code coverage report. -->
                                <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <id>surefire-unit-tests</id>
                            <phase>test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                            <configuration>
                                <!-- Sets the VM argument line used when unit tests are run. -->
                                <argLine>${surefireArgLine}</argLine>
                                <!-- Skips unit tests if the value of skip.unit.tests property is 
                                    true -->
                                <skipTests>${skip.unit.tests}</skipTests>
                                <!-- Excludes integration tests when unit tests are run. -->
                                <skip>false</skip>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.19.1</version>
                    <executions>
                        <!-- Ensures that both integration-test and verify goals of the Failsafe 
                            Maven plugin are executed. -->
                        <execution>
                            <id>integration-tests</id>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                            <configuration>
                                <!-- Sets the VM argument line used when integration tests are run. -->
                                <argLine>${failsafeArgLine}</argLine>
                                <!-- Skips integration tests if the value of skip.integration.tests 
                                    property is true -->
                                <skipTests>${skip.integration.tests}</skipTests>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>

当我使用maven目标clean install -P test-coverage

When I run my jenkins job with maven goal clean install -P test-coverage

我在Jenkins日志中看到了这一点:

I See this in my Jenkins log:

`[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] **/target/coverage-reports/jacoco-ut.exec;**/target/classes;**/src/main/java; locations are configured
[JaCoCo plugin] Number of found exec files for pattern **/target/coverage-reports/jacoco-ut.exec: 0
[JaCoCo plugin] Saving matched execfiles:  
[JaCoCo plugin] Saving matched class directories for class-pattern: **/target/classes: 
[JaCoCo plugin] Saving matched source directories for source-pattern: **/src/main/java: 
[JaCoCo plugin] Loading inclusions files..
[JaCoCo plugin] inclusions: []
[JaCoCo plugin] exclusions: []
[JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=0, minMethod=0, maxMethod=0, minLine=0, maxLine=0, minBranch=0, maxBranch=0, minInstruction=0, maxInstruction=0, minComplexity=0, maxComplexity=0]
[JaCoCo plugin] Publishing the results..
[JaCoCo plugin] Loading packages..
[JaCoCo plugin] Done.
[JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 0, instruction: 0`

这是我对Jacoco的Jenkins配置的样子:

This is how my Jenkins configuration for Jacoco looks like:

推荐答案

在我的情况下,我使用的是jacocoant 0.6,而jenkins的jaCoCo插件为2.2.0. 从jaCoCo插件的github页面:

In my case I was using jacocoant 0.6 and the jaCoCo plugin for jenkins was 2.2.0. From the jaCoCo plugin github page:

2.0.0及更高版本要求使用JaCoCo 0.7.5或更高版本,如果您的项目仍使用JaCoCo 0.7.4,则该插件将不再显示任何代码覆盖率数字!在这种情况下,请使用1.0.19版,直到可以在代码库中更新jacoco为止. https://github.com/jenkinsci/jacoco-plugin

Version 2.0.0 and higher requires using JaCoCo 0.7.5 or newer, if your projects still use JaCoCo 0.7.4, the plugin will not display any code-coverage numbers any more! In this case please use version 1.0.19 until you can update jacoco in your codebase. https://github.com/jenkinsci/jacoco-plugin

这篇关于Jacoco代码覆盖率显示Jenkins覆盖率为0%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆