简体   繁体   中英

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. Client is Jenkins and server(jacoco agent jar is present here) is a VM. This was not happening when I was using old version of jacoco 0.7.4.

在此处输入图像描述

Jenkins CI logs -

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. Using combination of ant and maven to dump exec file.

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.

" Invalid byte 1 of 1-byte UTF-8 sequence "; suggests like a bad file format, typically a BOM . Check if correct using file.

You'd specify 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.

The second is the same file, converted without 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)?

btw: Jacoco
Release 0.7.4 (2015/02/26)
Release 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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