Java.lang.IllegalStateException: 无法解析 JaCoCo XML 报告:jacoco.exec

huangapple go评论75阅读模式
英文:

Java.lang.IllegalStateException: Failed to parse JaCoCo XML report: jacoco.exec

问题

我正在尝试发布由Jacoco插件生成的覆盖率报告 - jacoco.exec。但是,我在提到的Sonar和Jacoco配置中遇到了以下异常。

SonarCube版本 6.7.7

[ERROR] 无法读取/导入覆盖率报告'jacoco.exec'。错误:{}
java.lang.IllegalStateException: 无法解析JaCoCo XML报告:jacoco.exec
	at org.sonar.plugins.jacoco.XmlReportParser.parse(XmlReportParser.java:96)
	at org.sonar.plugins.jacoco.JacocoSensor.importReport(JacocoSensor.java:73)
	...

Caused by: javax.xml.stream.XMLStreamException: java.nio.charset.MalformedInputException: 输入长度 = 1
	...
Caused by: java.nio.charset.MalformedInputException: 输入长度 = 1
	...

Sonar配置
在Maven中提到的Sonar插件的配置细节:

<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.jacoco.itReportPath>target/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.language>java</sonar.language>
<sonar.verbose>true</sonar.verbose>
<sonar.java.source>8</sonar.java.source>

Jacoco配置
在Maven中提到的Jacoco插件的配置细节:

<org.jacoco.version>0.8.1</org.jacoco.version>
<profile>
    <id>sonar-coverage</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>3.3.0.603</version>
            </plugin>
        </plugins>
    </build>
</profile>
<profile>
    <id>jacoco</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${org.jacoco.version}</version>
                <configuration>
                    <append>true</append>
                </configuration>
                <executions>
                    ...
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

我是否在Sonar或Jacoco的配置中遗漏了任何内容?

英文:

I am trying to publish my coverage report generated by Jacoco plugin - jacoco.exec. But I get the below exception with the mentioned sonar and Jacoco configuration.

SonarCube version 6.7.7

[ERROR] Coverage report &#39;jacoco.exec&#39; could not be read/imported. Error: {}
java.lang.IllegalStateException: Failed to parse JaCoCo XML report: jacoco.exec
	at org.sonar.plugins.jacoco.XmlReportParser.parse(XmlReportParser.java:96)
	at org.sonar.plugins.jacoco.JacocoSensor.importReport(JacocoSensor.java:73)
	at org.sonar.plugins.jacoco.JacocoSensor.importReports(JacocoSensor.java:64)
	at org.sonar.plugins.jacoco.JacocoSensor.execute(JacocoSensor.java:48)
	at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:53)
	at org.sonar.scanner.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:88)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:82)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:68)
	at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:88)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:177)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:291)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:286)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:264)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121)
	at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy24.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:65)
	at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:104)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: javax.xml.stream.XMLStreamException: java.nio.charset.MalformedInputException: Input length = 1
	at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.setInputSource(XMLStreamReaderImpl.java:212)
	at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.&lt;init&gt;(XMLStreamReaderImpl.java:184)
	at com.sun.xml.internal.stream.XMLInputFactoryImpl.getXMLStreamReaderImpl(XMLInputFactoryImpl.java:262)
	at com.sun.xml.internal.stream.XMLInputFactoryImpl.createXMLStreamReader(XMLInputFactoryImpl.java:134)
	at org.sonar.plugins.jacoco.XmlReportParser.parse(XmlReportParser.java:46)
	... 56 common frames omitted
Caused by: java.nio.charset.MalformedInputException: Input length = 1
	at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
	at java.io.InputStreamReader.read(InputStreamReader.java:184)
	at java.io.BufferedReader.fill(BufferedReader.java:161)
	at java.io.BufferedReader.read1(BufferedReader.java:212)
	at java.io.BufferedReader.read(BufferedReader.java:286)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1895)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(XMLEntityScanner.java:1761)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java:1829)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$XMLDeclDriver.next(XMLDocumentScannerImpl.java:749)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.setInputSource(XMLStreamReaderImpl.java:202)
	... 60 common frames omitted

Sonar Configuration:
Configuration details of sonar plugin mentioned in maven

&lt;sonar.jacoco.reportPath&gt;target/jacoco.exec&lt;/sonar.jacoco.reportPath&gt;
&lt;sonar.jacoco.itReportPath&gt;target/jacoco-it.exec&lt;/sonar.jacoco.itReportPath&gt;
&lt;sonar.language&gt;java&lt;/sonar.language&gt;
&lt;sonar.verbose&gt;true&lt;/sonar.verbose&gt;
&lt;sonar.java.source&gt;8&lt;/sonar.java.source&gt;

Jacoco Configuration
Configuration details of Jacoco plugin mentioned in maven

      &lt;org.jacoco.version&gt;0.8.1&lt;/org.jacoco.version&gt;
      &lt;profile&gt;
            &lt;id&gt;sonar-coverage&lt;/id&gt;
            &lt;activation&gt;
                &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
            &lt;/activation&gt;
        &lt;build&gt;
            &lt;plugins&gt;
                &lt;plugin&gt;
                    &lt;groupId&gt;org.sonarsource.scanner.maven&lt;/groupId&gt;
                    &lt;artifactId&gt;sonar-maven-plugin&lt;/artifactId&gt;
                    &lt;version&gt;3.3.0.603&lt;/version&gt;
                &lt;/plugin&gt;
            &lt;/plugins&gt;
        &lt;/build&gt;
    &lt;/profile&gt;

    &lt;profile&gt;
        &lt;id&gt;jacoco&lt;/id&gt;
        &lt;build&gt;
            &lt;plugins&gt;
                &lt;plugin&gt;
                    &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
                    &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
                    &lt;version&gt;${org.jacoco.version}&lt;/version&gt;
                    &lt;configuration&gt;
                        &lt;append&gt;true&lt;/append&gt;
                    &lt;/configuration&gt;
                    &lt;executions&gt;
                        &lt;execution&gt;
                            &lt;id&gt;agent-for-unit-test&lt;/id&gt;
                            &lt;goals&gt;
                                &lt;goal&gt;prepare-agent&lt;/goal&gt;
                            &lt;/goals&gt;
                        &lt;/execution&gt;
                        &lt;execution&gt;
                            &lt;id&gt;agent-for-integration-test&lt;/id&gt;
                            &lt;phase&gt;verify&lt;/phase&gt;
                            &lt;goals&gt;
                                &lt;goal&gt;prepare-agent-integration&lt;/goal&gt;
                            &lt;/goals&gt;
                        &lt;/execution&gt;
                        &lt;execution&gt;
                            &lt;id&gt;jacoco-site&lt;/id&gt;
                            &lt;phase&gt;verify&lt;/phase&gt;
                            &lt;goals&gt;
                                &lt;goal&gt;report&lt;/goal&gt;
                            &lt;/goals&gt;
                        &lt;/execution&gt;
                    &lt;/executions&gt;
                &lt;/plugin&gt;
            &lt;/plugins&gt;
        &lt;/build&gt;
    &lt;/profile&gt;    

Am I missing any configuration in sonar or jacoco?

答案1

得分: 5

> java.lang.IllegalStateException: 解析JaCoCo XML报告失败:jacoco.exec
> ...
> 原因是:javax.xml.stream.XMLStreamException: java.nio.charset.MalformedInputException: 输入长度 = 1

错误表明在解析XML时找到了不受支持的字符,文件为 jacoco.exec
这是因为 jacoco.exec 是二进制文件,而不是xml。

此外,Sonar已不再支持jacoco.exec
我建议您参考在xml格式中导入jacoco覆盖率报告
从上面的链接中:

> 默认情况下,生成的报告将保存在 target/site/jacoco/jacoco.xml 下;sonar-jacoco插件会自动检查此位置,无需进一步配置。只需像往常一样运行 mvn sonar:sonar,报告就会被获取。

英文:

> java.lang.IllegalStateException: Failed to parse JaCoCo XML report: jacoco.exec
> ...
> Caused by: javax.xml.stream.XMLStreamException: java.nio.charset.MalformedInputException: Input length = 1

The error indicates that unsupported character is found when parsing XML, and the file is jacoco.exec.
It is because jacoco.exec is binary, not xml.

In addition Sonar has deprecated the support of jacoco.exec.
I suggest you to follow coverage-test-data-importing-jacoco-coverage-report-in-xml-format.
From the link above:

> By default the generated report will be saved under target/site/jacoco/jacoco.xml; this location will be checked automatically by the sonar-jacoco plugin so no further configuration is required. Just launch mvn sonar:sonar as usual and the report will be picked up.

huangapple
  • 本文由 发表于 2020年3月16日 18:58:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/60704682.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定