Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jacoco's prepare-agent not generating jacoco.exec file

Tags:

maven

jacoco

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?

like image 774
Gili Avatar asked Feb 07 '14 16:02

Gili


People also ask

How do I create a JaCoCo exec file?

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.

How do I find the JaCoCo exec file?

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.

Where does JaCoCo generate report?

By default, a HTML report is generated at $buildDir/reports/jacoco/test .

What is org JaCoCo agent?

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.


1 Answers

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.

like image 196
Gili Avatar answered Nov 05 '22 11:11

Gili