Analyzing code across modules

3,173 views
Skip to first unread message

vlad....@originate.com

unread,
Jul 27, 2016, 6:12:33 PM7/27/16
to JaCoCo and EclEmma Users
We have a multi-module Maven project where some of the unit/integration tests are in a different module than the code they are testing. I know this is non-standard but it isn't straightforward to put the tests into the right module because of dependency issues. Is there a way to get JaCoCo to analyze across modules so that it picks up the tests in the other module when it analyzes the source code?

Evgeny Mandrikov

unread,
Jul 28, 2016, 10:47:26 AM7/28/16
to JaCoCo and EclEmma Users, vlad....@originate.com
Hi,

Such scenario is supported starting from JaCoCo version 0.7.7 - see http://www.eclemma.org/jacoco/trunk/doc/report-aggregate-mojo.html
You can find an example of project in our integration tests - https://github.com/jacoco/jacoco/tree/v0.7.7/jacoco-maven-plugin.test/it/it-report-aggregate
Also JaCoCo itself has tests in a modules different from the modules with main code and hence uses this feature during build - see https://github.com/jacoco/jacoco/blob/v0.7.7/org.jacoco.doc/pom.xml#L110-L135
Message has been deleted

vlad....@originate.com

unread,
Jul 30, 2016, 6:44:20 PM7/30/16
to JaCoCo and EclEmma Users, vlad....@originate.com

Thanks for the info. I tried to get it to work but I couldn't. Here are the things I tried:

1. Building the entire jacoco project using `mvn clean org.jacoco:jacoco-maven-plugin:report-aggregate install` and then `mvn sonar:sonar`. However, when I browsed the sonar report I did not see "JaCoCo :: Test :: Maven Plugin" in the list of modules.

2. Running the report-aggregate command in the jacoco-maven-plugin.test directory. However, when I ran `mvn sonar:sonar` it skipped sonar.

3. Copying the it-report-aggregate directory and creating a separate mvn project (modifying the pom artifacts/versions and adding junit dependencies as necessary so that I could build it by itself). When I did that I was able to get a sonar report for code coverage, but the report indicated coverage only for Example1a, not for Example1b.

Is there a simple example of a standalone mvn project that shows how this could work? Something similar to it-report-aggregate.

Thanks,
Vlad

Evgeny Mandrikov

unread,
Jul 31, 2016, 3:14:51 PM7/31/16
to JaCoCo and EclEmma Users, vlad....@originate.com
First of all - JaCoCo integration into SonarQube is not developed by JaCoCo Team, so if your question is about SonarQube (initial question contained nothing about it), then http://www.sonarqube.org/get-support/

Speaking solely about JaCoCo: in attachment you'll find an example of project - after execution of "mvn clean verify" JaCoCo will generate report in directory "tests/target/site/jacoco-aggregate".

As a bonus: "code/pom.xml" contains property "sonar.jacoco.reportPath", so that "mvn clean verify sonar:sonar" should also work.
example.zip

vlad....@originate.com

unread,
Aug 1, 2016, 6:07:21 PM8/1/16
to JaCoCo and EclEmma Users, vlad....@originate.com
OK, I think I see how it works. What if some of the unit tests are in the same module as the source code, and some are in a different module? In the example provided, if I add a new method to Example.java and then add a unit test for it in the code module, jacoco's analysis won't pick it up since sonar.jacoco.reportPath points to the tests module. Or is that handled outside of jacoco entirely?

Thanks,
Vlad

Evgeny Mandrikov

unread,
Aug 2, 2016, 4:09:54 AM8/2/16
to JaCoCo and EclEmma Users, vlad....@originate.com
Once again: integration of JaCoCo into SonarQube is not part of JaCoCo project, it is developed separately on top of APIs provided by JaCoCo - https://github.com/SonarSource/sonar-java/tree/master/java-jacoco Property "sonar.jacoco.reportPath" is SonarQube property, would be better to use SonarQube communication channels for questions about SonarQube.

During analysis of classes of some module SonarQube will load information about coverage for these classes from the file specified in property "sonar.jacoco.reportPath" for this module. Thus if during execution of all tests for this module you will instruct JaCoCo to write to the same file, then SonarQube will be able to load this.

If we talk solely about JaCoCo and its jacoco-maven-plugin, then such scenario is also supported by http://www.eclemma.org/jacoco/trunk/doc/report-aggregate-mojo.html without writing into the same file.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages