generating sonar coverage reports for unit and integration tests
<p>I have looked a while at different articles and answers on stackoverflow but I have yet to find a working solution for my case. Definitely something wrong with my understanding of how jacoco, maven and sonar all come together to create the reports, so I'm going to ask for help.</p>

<p>I have a multi-module maven project with the following structure(simplified a little):</p>

<pre><code>root-folder/
├── module1/
│   ├── module1_1/
│   ├── module2_2/
├── module2/
│   ├── module2_1/
│   └── module2_2/
├── module3/
│   ├── module3_1/
│       ├── module3_1_1/
│   └── module3_2/
│   └── module3_3/
│   └── module3_4/
├── parent/
├── itest/
│   ├── itest_helper1/
│   └── itest_helper2/
│   └── actual_tests/
├── module4/
</code></pre>

<p>Allow me to expand a little. The parent module is just a pom with the entire dependencies and their versions. This pom is used as a parent to every other module of level1 (directly under root). Module 3_1_1 for example has parent module3_1/pom, which in turn has parent/pom. I also have a feature module which I excluded because it is used for exposing modules to other projects, which won't be of use in my case. </p>

<p>Most modules, but not all of them, have unit tests using junit framework. The integration tests are in a separate module which has a few helper submodules and a submodule with actual ITests classes. My itests cover code from all across my project, so they test code from all other modules.</p>

<p>My root pom also has as parent some internal framework that is basically an osgi container, web service and handles 3rd party dependencies.</p>

<p>I have sonar version 5.6 and have failed to create reports for integration tests. I also wish they are merged so I can drilldown and view test coverage per module/class. I have tried different options and setups, and my latest attempt has the following in my root-folder/pom.xml.</p>

<pre><code> &lt;!-- properties section--&gt;
  &lt;properties&gt;
        &lt;jacoco.version&gt;0.7.2.201409121644&lt;/jacoco.version&gt;
        &lt;sonar.language&gt;java&lt;/sonar.language&gt;
        &lt;sonar.sourceEncoding&gt;UTF-8&lt;/sonar.sourceEncoding&gt;
        &lt;sonar.java.coveragePlugin&gt;jacoco&lt;/sonar.java.coveragePlugin&gt;
        &lt;jacoco.outputDir&gt;${project.build.directory}&lt;/jacoco.outputDir&gt;
        &lt;jacoco.out.ut.file&gt;jacoco-ut.exec&lt;/jacoco.out.ut.file&gt;
        &lt;sonar.jacoco.reportPath&gt;${jacoco.outputDir}/${jacoco.out.ut.file}&lt;/sonar.jacoco.reportPath&gt;
        &lt;jacoco.out.it.file&gt;jacoco-it.exec&lt;/jacoco.out.it.file&gt;
        &lt;sonar.jacoco.itReportPath&gt;${jacoco.outputDir}/${jacoco.out.it.file}&lt;/sonar.jacoco.itReportPath&gt;
    &lt;/properties&gt;

&lt;!-- plugins section--&gt;
&lt;profiles&gt;
        &lt;profile&gt;
            &lt;id&gt;coverage&lt;/id&gt;
            &lt;build&gt;
                &lt;plugins&gt;
                    &lt;plugin&gt;
                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                        &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                        &lt;configuration&gt;
                            &lt;argLine&gt;${jacoco.agent.ut.arg}&lt;/argLine&gt;
                            &lt;!-- test failure ignore --&gt;
                            &lt;testFailureIgnore&gt;true&lt;/testFailureIgnore&gt;
                            &lt;includes&gt;
                                &lt;include&gt;**/*Test*&lt;/include&gt;
                            &lt;/includes&gt;
                        &lt;/configuration&gt;
                    &lt;/plugin&gt;
                    &lt;plugin&gt;
                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                        &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
                        &lt;configuration&gt;
                            &lt;argLine&gt;-Xmx1024m -XX:MaxPermSize=256m ${jacoco.agent.it.arg}
                            &lt;/argLine&gt;
                            &lt;!-- Let's put failsafe reports with surefire to have access to tests
                                failures/success reports in sonar --&gt;
                            &lt;reportsDirectory&gt;${project.build.directory}/surefire-reports
                            &lt;/reportsDirectory&gt;
                            &lt;includes&gt;
                                &lt;include&gt;**/*IT*&lt;/include&gt;
                            &lt;/includes&gt;
                        &lt;/configuration&gt;
                    &lt;/plugin&gt;
                    &lt;plugin&gt;
                        &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
                        &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
                        &lt;version&gt;${jacoco.version}&lt;/version&gt;
                        &lt;executions&gt;
                            &lt;!-- Prepares a variable, jacoco.agent.ut.arg, that contains the info
                                to be passed to the JVM hosting the code being tested. --&gt;
                            &lt;execution&gt;
                                &lt;id&gt;prepare-ut-agent&lt;/id&gt;
                                &lt;phase&gt;process-test-classes&lt;/phase&gt;
                                &lt;goals&gt;
                                    &lt;goal&gt;prepare-agent&lt;/goal&gt;
                                &lt;/goals&gt;
                                &lt;configuration&gt;
                                    &lt;destFile&gt;${sonar.jacoco.reportPath}&lt;/destFile&gt;
                                    &lt;propertyName&gt;jacoco.agent.ut.arg&lt;/propertyName&gt;
                                    &lt;append&gt;true&lt;/append&gt;
                                &lt;/configuration&gt;
                            &lt;/execution&gt;
                            &lt;!-- Prepares a variable, jacoco.agent.it.arg, that contains the info
                                to be passed to the JVM hosting the code being tested. --&gt;
                            &lt;execution&gt;
                                &lt;id&gt;prepare-it-agent&lt;/id&gt;
                                &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                                &lt;goals&gt;
                                    &lt;goal&gt;prepare-agent&lt;/goal&gt;
                                &lt;/goals&gt;
                                &lt;configuration&gt;
                                    &lt;destFile&gt;${sonar.jacoco.itReportPath}&lt;/destFile&gt;
                                    &lt;propertyName&gt;jacoco.agent.it.arg&lt;/propertyName&gt;
                                    &lt;append&gt;true&lt;/append&gt;
                                &lt;/configuration&gt;
                            &lt;/execution&gt;
                        &lt;/executions&gt;
                    &lt;/plugin&gt;
                &lt;/plugins&gt;
            &lt;/build&gt;
        &lt;/profile&gt;
        &lt;!-- Integraton tests --&gt;
        &lt;profile&gt;
            &lt;id&gt;run-its&lt;/id&gt;
            &lt;build&gt;
                &lt;plugins&gt;
                    &lt;plugin&gt;
                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                        &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
                        &lt;executions&gt;
                            &lt;execution&gt;
                                &lt;id&gt;integration-test&lt;/id&gt;
                                &lt;phase&gt;integration-test&lt;/phase&gt;
                                &lt;goals&gt;
                                    &lt;goal&gt;integration-test&lt;/goal&gt;
                                &lt;/goals&gt;
                            &lt;/execution&gt;
                            &lt;execution&gt;
                                &lt;id&gt;verify&lt;/id&gt;
                                &lt;phase&gt;verify&lt;/phase&gt;
                                &lt;goals&gt;
                                    &lt;goal&gt;verify&lt;/goal&gt;
                                &lt;/goals&gt;
                            &lt;/execution&gt;
                        &lt;/executions&gt;
                    &lt;/plugin&gt;
                &lt;/plugins&gt;
            &lt;/build&gt;
        &lt;/profile&gt;
    &lt;/profiles&gt;
</code></pre>

<p>I run my project with mvn -Pcoverage,run-its clean install sonar:sonar. My unit tests seem to be ok, with full coverage and success rate. To be honest I am only interested in integration tests, but unit-test are pretty easy to setup so I added them also. For my integration tests report, it actually reports coverage of my itest module, which is the only one that shouldn't be reported. I want my itests to report coverage for my entire project.</p>

<p>Here is the jacoco part from sonar running over my itest module:</p>

<pre><code>    [WARNING] You are not using the latest JaCoCo binary format version, please     consider upgrading to latest JaCoCo version.
[INFO] Analysing  D:\Home\project\root\itest\testcase\target\jacoco-it.exec
[WARNING] You are not using the latest JaCoCo binary format version, please consider upgrading to latest JaCoCo version.
[INFO] Analysing D:\Home\project\root\itest\testcase\target\sonar\jacoco-overall.exec
[INFO] No information about coverage per test.
</code></pre>

<p>Also since my plugin configuration is in the very root pom, it tries to analyse reports for all my modules (including ones that don't have unit tests) and throws an error in the sonar run log, but I assume it isn't an issue. Any help is much appreciated, please ask for more details if you need them. Thanks.</p>