jenkins - Jacoco 代码覆盖率在 Jenkins 上显示覆盖率为 0%

标签 jenkins maven-2 code-coverage jacoco jacoco-maven-plugin

我已阅读了类似问题的大部分答案,但没有一个适合回答我的问题。

我的 pom 文件中的配置文件如下所示:

            <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 目标运行 jenkins 作业时 clean install -P test-coverage

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

`[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 配置:

enter image description here

最佳答案

就我而言,无法获取执行文件。

这是因为我的构建目录与 Jenkins 作业的工作空间不同。当我将构建目录更改为工作空间时,奇迹发生了。

关于jenkins - Jacoco 代码覆盖率在 Jenkins 上显示覆盖率为 0%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41673427/

相关文章:

jenkins - 解决 Jenkins 缓慢问题

Jenkins :让一个工作等待另一个工作正在运行

node.js - 如何解决 npm install 在非 MAC 操作系统上抛出 fsevents 警告?

maven-2 - Maven2 无法从相对路径中找到父级

unit-testing - Gradle jacoco 代码覆盖率 - 然后在 Jenkins 中发布/显示

jenkins - 在 Jenkins 中禁用 ping 从站

java - 如何将本地 .m2 存储库的所有 Artifact 发布到 jfrog 存储库

maven-2 - Jasper Reports 的 Maven 存储库是什么?

TFS 2015 中的 Javascript 单元测试代码覆盖率

code-coverage - java.lang.IllegalStateException : JMockit wasn't properly initialized; check that jmockit. jar 在类路径中位于 junit.jar 之前