I'm currently trying to add JaCoCo as a dependency on my spring boot maven project to see the code coverage for my unit tests. However, when I run the tests, it fails with error.
Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.3:report (report) on project test-rest-service: An error has occurred in JaCoCo report generation. Error while creating report: malformed input around byte 2 -> [Help 1]
All tests passes without failure so that isn't a problem.
The dependency for JaCoCo is:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
The JaCoCo.exec file is produced but I can't open it to generate the report. What am I doing wrong?
At least in my case it was more straightforward. I just had to run mvn clean verify and everything worked again without any issues.
I've been having a similar problem. I'm writing even though the question is months old as it was very time consuming to figure out and no amount of googling provided me with a straight answer but only to clues I had to piece together myself.
In my case the error happened roughly once every three builds. The error also wasn't always the same as stated in this question: the byte number was changing and sometimes I just got an EOFException instead.
There is a degree of guesswork in my assessment. Here follows the bottomline of my investigation:
JaCoCo.exec
file, probably due to the corresponding VM being terminated before the write operation completes (or starts). To note that JaCoCo writes said file only when the VM is exiting.maven-surefire-plugin
or maven-failsafe-plugin
to trigger. Make sure all your threads run to completion.forkedProcessExitTimeoutInSeconds
option to a value greater than the default 30
seconds (or otherwise greater than what you have currently set) in your maven-surefire-plugin
or maven-failsafe-plugin
. This was my case, as I was forced to run the build against a very slow and memory-constrained VM.forkCount
property is greater than 0
in your maven-surefire-plugin
or maven-failsafe-plugin
and that forkMode
is NOT set to never
as JaCoCo needs to work on a forked process in order for the file to be written and therefore picked up afterwards.Example snippet:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<forkedProcessExitTimeoutInSeconds>60</forkedProcessExitTimeoutInSeconds>
<forkCount>1</forkCount>
</configuration>
</plugin>
References:
In my case, the error was not very helpful:
Execution jacoco-site of goal org.jacoco:jacoco-maven-plugin:0.8.3:report-aggregate failed: malformed input off : 61255, length : 1: Input length = 1 -> [Help 1]
I had to debug the plugin execution and found that org.jacoco.core.analysis.Analyzer was picking non .class files from target/classes folder that I had there like templates, etc. Some of them were raising a MalformedInputException about incorrect charset. The fix was to include only .class files in plugin configuration:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With