I am running Jacoco's Maven plugin. The prepare-agent
goal runs fine, but does not generate jacoco.exec
file for some reason. Subsequently the report
goal complains Skipping JaCoCo execution due to missing execution data file
.
Any ideas?
For generating JaCoCo reports only run the maven build with profile jacoco-generate-report as it is shown in the example above. After the command was executed, in directory target/jacoco-report you can find reports in HTML and XML formats.
In IntelliJ Idea from the menu select Analyze > Show Coverage data . In the new window press the + button and select your . exec file. The test coverage results will appear in the editor Coverage tab.
By default, a HTML report is generated at $buildDir/reports/jacoco/test .
JaCoCo uses class file instrumentation to record execution coverage data. Class files are instrumented on-the-fly using a so called Java agent. This mechanism allows in-memory pre-processing of all class files during class loading independent of the application framework.
Having read https://groups.google.com/forum/#!topic/jacoco/LzmCezW8VKA, it turns out that prepare-agent
sets a surefire property called argLine
. If you override this property (something that https://issues.apache.org/jira/browse/SUREFIRE-951 encourages you to do) then jacoco never ends up running.
The solution is to replace:
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
with
<argLine>-Dfile.encoding=${project.build.sourceEncoding} ${argLine}</argLine>
Meaning, append jacoco's argLine
to the new value.
UPDATE: As pointed out by Fodder, if you aren't always running JaCoCo and no other plugin sets ${argLine}
then Maven will complain that ${argLine}
is undefined. To resolve this, simply define what ${argLine}
should look like when JaCoCo is skipped:
<properties>
<argLine/>
</properties>
In this case use @{argLine} instead of ${argLine} as explained here.
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