JaCoCo doesn't get along with JMockIt

3,538 views
Skip to first unread message

trey.hu...@gmail.com

unread,
Jun 5, 2013, 11:47:13 AM6/5/13
to jac...@googlegroups.com
I am battling with getting JMockIt and JaCoCo to live in the same maven pom and work together. I understand that each tool uses a java agent to "get things done", and that I should use JaCoCo in "offline" mode (yes I understand this mode is discouraged). But I haven't been able to find any actual documentation of how to set up JaCoCo for offline instrumentation when used from maven.

So can anyone help me get me started with setting up JaCoCo correctly in my pom?

Also, are there any plans to help JaCoCo cooperate with other instrumentation tools?

Marc R. Hoffmann

unread,
Jun 5, 2013, 3:31:59 PM6/5/13
to jac...@googlegroups.com
Hi,

the Maven goals for offline instrumentation are documented:

http://www.eclemma.org/jacoco/trunk/doc/instrument-mojo.html

http://www.eclemma.org/jacoco/trunk/doc/restore-instrumented-classes-mojo.html

There is also an example:

http://www.eclemma.org/jacoco/trunk/doc/examples/build/pom-offline.xml

I would love to work on solutions to work with other tools but the
limited resources do not allow any realistic plans.

Best regards,
-marc

trey.hu...@gmail.com

unread,
Jun 5, 2013, 3:46:23 PM6/5/13
to jac...@googlegroups.com
Thanks for the help. I've seen the documentation, but I couldn't piece together the correct maven configuration to get it working correctly.

I borrowed snippets from your linked pom-offline.xml, and now the tests execute correctly and the JaCoCo report is also built. However, all of the coverage is zero. Have any clue why that may be happening?

Marc Hoffmann

unread,
Jun 6, 2013, 5:16:59 AM6/6/13
to jac...@googlegroups.com
Some things to check:

1) Are the classes under test listed in the "Sessions" page (link in
top right corner of the report)?
2) Did you also configure the restore-instrumented-classes goal?
3) If you use the latest JaCoCo version 0.6.3 you will get better error
messages in case of misconfiguration.

Best regards,
-marc

Evgeny Mandrikov

unread,
Jun 7, 2013, 9:39:51 AM6/7/13
to jac...@googlegroups.com
Hi,

FYI I've just created an example https://github.com/Godin/jacoco-experiments/tree/master/jacoco-jmockit-example "mvn clean package" will execute test and generate coverage report.
This is simply combination of two examples - JMockit and JaCoCo offline instrumentation, but with some comments.
Hope it may help.

trey.hu...@gmail.com

unread,
Jun 20, 2013, 9:50:32 AM6/20/13
to jac...@googlegroups.com
Evgeny, thanks for the help. I pulled down the example project and ran it, however no coverage report is generated. The pom doesn't have a reporting section. So I added a reporting section, and the site goal fails with the message "Class Utils is already instrumented". Here's the reporting section I've added to the pom:

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.4</version>
<configuration>
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.12.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</plugin>
</plugins>
</reporting>

Can you please expand on the example so that the coverage report is generated? It would help a great deal. Thank you very much.

Evgeny Mandrikov

unread,
Jun 20, 2013, 9:55:45 AM6/20/13
to jac...@googlegroups.com, trey.hu...@gmail.com
Hi,

Please watch carefully - my example generates report using "report" goal of jacoco-maven-plugin, but this is done not thru reporting section (since I don't like maven-site-plugin). I don't know when I'll have time to take a look into your issue with reporting section as I'm quite busy now - sorry.

trey.hu...@gmail.com

unread,
Jun 20, 2013, 10:28:38 AM6/20/13
to jac...@googlegroups.com, trey.hu...@gmail.com
Thanks for the response and the effort. However, the example still fails with the same error message "Class x is already instrumented" when using the following maven command: mvn clean test jacoco:report

Evgeny Mandrikov

unread,
Jun 20, 2013, 10:33:27 AM6/20/13
to jac...@googlegroups.com, trey.hu...@gmail.com
As I said in my first email - use "mvn clean package".

trey.hu...@gmail.com

unread,
Jun 20, 2013, 10:53:42 AM6/20/13
to jac...@googlegroups.com, trey.hu...@gmail.com
I see no report when I use those arguments. Where is the report supposed to be generated?

Evgeny Mandrikov

unread,
Jun 20, 2013, 10:58:09 AM6/20/13
to jac...@googlegroups.com, trey.hu...@gmail.com
Oh, excuse me: it should be "mvn clean install" and report will be in "target/site/jacoco".

trey.hu...@gmail.com

unread,
Jun 20, 2013, 12:01:21 PM6/20/13
to jac...@googlegroups.com, trey.hu...@gmail.com
That did the trick. Thanks for the help.

trey.hu...@gmail.com

unread,
Jun 20, 2013, 4:02:46 PM6/20/13
to jac...@googlegroups.com, trey.hu...@gmail.com
So having to run "mvn clean install" was not going to work for us. I had to figure out the correct pom configuration to have the classes instrumented and the report generated on the build machine, and still support site reporting and artifact deployment. I ended up with the following:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>

<executions>
<execution>
<id>instrument</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore</id>
<phase>prepare-package</phase>
<goals>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

This plugin configuration will generate the report automatically as part of the package goal, and doesn't break the other goals.

Thanks for the help Evgeny

Evgeny Mandrikov

unread,
Jun 21, 2013, 3:15:56 AM6/21/13
to jac...@googlegroups.com, trey.hu...@gmail.com
Glad to hear that you managed to find solution. I inserted your pom-snippet into example. Thanks.

Marc Hoffmann

unread,
Jun 21, 2013, 5:17:27 AM6/21/13
to jac...@googlegroups.com
FYI, the failure is a new "feature" of 0.6.3, see
https://github.com/jacoco/jacoco/issues/108

Creating a report on instrumented classes it a configuration error and
would result in a 0% coverage report. That's why I introduced a check
that instrumented classes cannot be analyzed.

Cheers,
-marc
> --
> You received this message because you are subscribed to the Google
> Groups "JaCoCo and EclEmma Users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to jacoco+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out
> [1].
>
>
>
> Links:
> ------
> [1] https://groups.google.com/groups/opt_out

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages