简体   繁体   English

Jacoco 0.8.7 显示代码覆盖率为零

[英]Jacoco 0.8.7 showing code coverage as zero

I am seeing code coverage as zero in jenkins plugin.我在詹金斯插件中看到代码覆盖率为零。 I am using Jacoco 0.8.7 in client server mode.我在客户端服务器模式下使用 Jacoco 0.8.7。 Client is Jenkins and server(jacoco agent jar is present here) is a VM.客户端是 Jenkins,服务器(这里有 jacoco 代理 jar)是一个虚拟机。 This was not happening when I was using old version of jacoco 0.7.4.当我使用旧版本的 jacoco 0.7.4 时,这并没有发生。

在此处输入图像描述

Jenkins CI logs -詹金斯 CI 日志 -

18:43:34 [INFO] Executing tasks
18:43:34 
18:43:34 main:
18:43:34      [echo] Generating JaCoCo Reports
18:43:34     [mkdir] Created dir: /testingService-ci-8554/workspace/job/target/coverage-report
18:43:34    [report] Loading execution data file /testingService-ci-8554/workspace/job/target/jacoco.exec
18:43:35    [report] Writing bundle 'testingService' with 4 classes
18:43:35 [INFO] Executed tasks
18:43:35 [INFO] ------------------------------------------------------------------------
18:43:35 [INFO] BUILD SUCCESS
18:43:35 [INFO] ------------------------------------------------------------------------
18:43:35 [INFO] Total time:  6.102 s
18:43:35 [INFO] Finished at: 2022-07-19T06:13:35-07:00
18:43:35 [INFO] ------------------------------------------------------------------------
18:43:36 Publishing Coverage report....
18:43:40 report /var/lib/jenkins/jobs/job/builds/34/jacoco.exec for Jacoco has met some errors: net.sf.saxon.trans.XPathException: I/O error reported by XML parser processing file:/var/lib/jenkins/jobs/job/builds/34/jacoco.exec: Invalid byte 1 of 1-byte UTF-8 sequence.
18:43:40 A total of 0 reports were found
18:43:40 [GitHub Checks] Causes for no suitable publisher found: 
18:43:40 [GitHub Checks] Trying to resolve checks parameters from GitHub SCM...
18:43:40 [GitHub Checks] Job does not use GitHub SCM
18:43:40 [GitHub Checks] Trying to resolve checks parameters from Git SCM...
18:43:40 [GitHub Checks] No credentials found
18:43:40 [GitHub Checks] Job does not have valid credentials
18:43:40 [Checks API] No suitable checks publisher found.
18:43:40 [htmlpublisher] Archiving HTML reports...
18:43:40 [htmlpublisher] Archiving at BUILD level /testingService-ci-8554/workspace/job/target/coverage-report/html to /var/lib/jenkins/jobs/job/builds/34/htmlreports/Coverage_20Report
18:43:40 [JaCoCo plugin] Collecting JaCoCo coverage data...
18:43:40 [JaCoCo plugin] **/**.exec;**/classes;**/src/main/java; locations are configured
18:43:43 [JaCoCo plugin] Number of found exec files for pattern **/**.exec: 1
18:43:43 [JaCoCo plugin] Saving matched execfiles:  /testingService-ci-8554/workspace/job/target/jacoco.exec
18:43:46 [JaCoCo plugin] Saving matched class directories for class-pattern: **/classes: 
18:43:47 [JaCoCo plugin]  - /testingService-ci-8554/workspace/job/cronus/scripts/app/classes 5 files
18:43:47 [JaCoCo plugin]  - /testingService-ci-8554/workspace/job/target/classes 5 files
18:43:50 [JaCoCo plugin] Saving matched source directories for source-pattern: **/src/main/java: 
18:43:50 [JaCoCo plugin] Source Inclusions: **/*.java
18:43:50 [JaCoCo plugin] Source Exclusions: 
18:43:50 [JaCoCo plugin] - /testingService-ci-8554/workspace/job/Runner/tests/fixtures/SampleProjects/helixProject/functionalTests/src/main/java 1 files
18:43:50 [JaCoCo plugin] - /testingService-ci-8554/workspace/job/testingServiceService/src/main/java 4 files
18:43:50 [JaCoCo plugin] Loading inclusions files..
18:43:50 [JaCoCo plugin] inclusions: []
18:43:50 [JaCoCo plugin] exclusions: []
18:43:50 [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]
18:43:50 [JaCoCo plugin] Publishing the results..
18:43:50 [JaCoCo plugin] Loading packages..
18:43:50 [JaCoCo plugin] Done.
18:43:50 [JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 100, instruction: 0

Jenkins CI plugin congiuration is like this. Jenkins CI 插件配置是这样的。 Using combination of ant and maven to dump exec file.使用 ant 和 maven 的组合来转储 ​​exec 文件。

echo '''
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.paypal</groupId>
  <artifactId>CodeCoverage</artifactId>
  <version>0.0.1</version>
  <build>
    <plugins>
      <!-- Dependencies -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <!-- Copy the ant tasks jar. Needed for ts.jacoco.report-ant . -->
          <execution>
            <id>jacoco-dependency-ant</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>process-test-resources</phase>
            <inherited>false</inherited>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.jacoco</groupId>
                  <artifactId>org.jacoco.ant</artifactId>
                  <version>0.8.7</version>
                </artifactItem>
              </artifactItems>
              <stripVersion>true</stripVersion>
              <outputDirectory>${basedir}/target/jacoco-jars</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.7</version>
        <executions>
          <execution>
            <id>default-cli</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>dump</goal>
            </goals>
            <configuration>
              <reset>${Reset}</reset>
              <address>${jacocoAgentHost}</address>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Ant plugin. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>report</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <property environment="env" />
                <!-- Execute an ant task within maven -->
                <echo message="Generating JaCoCo Reports" />
                <taskdef name="report" classname="org.jacoco.ant.ReportTask">
                  <classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar" />
                </taskdef>
                <mkdir dir="${basedir}/target/coverage-report" />
                <report>
                  <executiondata>
                    <fileset dir="${basedir}/target">
                      <include name="jacoco.exec" />
                    </fileset>
                  </executiondata>
                  <structure name="Raptor Coverage Project">
                    <group name="${env.appName}">
                      <classfiles>
                        <fileset dir="target/classes">
                        <exclude name=""/>

                        </fileset>
                      </classfiles>
                      <sourcefiles encoding="UTF-8">
                        <fileset dir="target/sources" />
                      </sourcefiles>
                    </group>
                  </structure>
                  <html destdir="${basedir}/target/coverage-report/html" />
                  <xml destfile="${basedir}/target/coverage-report/coverage-report.xml" />
                  <csv destfile="${basedir}/target/coverage-report/coverage-report.csv" />
                </report>
              </target>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.ant</artifactId>
            <version>0.8.7</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>''' > jacoco_pom.xml

This is not an answer, just a formatted response to OP's comment for elaboration.这不是答案,只是对 OP 评论的格式化回复以供详细说明。

" Invalid byte 1 of 1-byte UTF-8 sequence "; " Invalid byte 1 of 1-byte UTF-8 sequence "; suggests like a bad file format, typically a BOM .建议像错误的文件格式,通常是BOM Check if correct using file.使用文件检查是否正确。

You'd specify file /path/to/filename.txt .您将指定file /path/to/filename.txt The first is likely what you'll see when there's a BOM (Byte Order Mark) , which would produce the error: Invalid byte 1 of 1-byte UTF-8 sequence.第一个可能是当有BOM (Byte Order Mark)时您会看到的,这会产生错误: Invalid byte 1 of 1-byte UTF-8 sequence.

The second is the same file, converted without BOM.第二个是相同的文件,没有 BOM 转换。

$ file jacoco.exec
jacoco.exec: Unicode text, UTF-8 (with BOM) text

$ file jacoco.exec
jacoco.exec: ASCII text

Once you determine the format is not correct, it's going to be up to you to determine how it's ending up that way and how to fix .一旦您确定格式不正确,您将自行决定如何以这种方式结束以及如何修复. Most likely it's a conversion issue moving files between OS.很可能是在操作系统之间移动文件的转换问题。

Are you running in a mixed environment or have moved from Win to Linux (or Mac; dunno)?您是在混合环境中运行还是已经从 Win 迁移到 Linux(或 Mac;不知道)?

btw: Jacoco顺便说一句:雅可可
Release 0.7.4 (2015/02/26)发布 0.7.4 (2015/02/26)
Release 0.8.7 (2021/05/04)发布 0.8.7 (2021/05/04)
incorporates so many changes, from Java8 to Java 18 support, changes to maven 3, ASM 5.0.1 to ASM 9.3, hard to say why it no longer accepting, assuming all you changed was the Jacoco version (it's never one thing).包含了很多变化,从 Java8 到 Java 18 支持,从 maven 3 到 ASM 5.0.1 到 ASM 9.3 的变化,很难说为什么它不再接受,假设你改变的只是 Jacoco 版本(它从来都不是一回事)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM