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.
I have a multi-module maven project with the following structure(simplified a little):
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/
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.
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.
My root pom also has as parent some internal framework that is basically an osgi container, web service and handles 3rd party dependencies.
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.
<!-- properties section-->
<properties>
<jacoco.version>0.7.2.201409121644</jacoco.version>
<sonar.language>java</sonar.language>
<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<jacoco.outputDir>${project.build.directory}</jacoco.outputDir>
<jacoco.out.ut.file>jacoco-ut.exec</jacoco.out.ut.file>
<sonar.jacoco.reportPath>${jacoco.outputDir}/${jacoco.out.ut.file}</sonar.jacoco.reportPath>
<jacoco.out.it.file>jacoco-it.exec</jacoco.out.it.file>
<sonar.jacoco.itReportPath>${jacoco.outputDir}/${jacoco.out.it.file}</sonar.jacoco.itReportPath>
</properties>
<!-- plugins section-->
<profiles>
<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${jacoco.agent.ut.arg}</argLine>
<!-- test failure ignore -->
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/*Test*</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>-Xmx1024m -XX:MaxPermSize=256m ${jacoco.agent.it.arg}
</argLine>
<!-- Let's put failsafe reports with surefire to have access to tests
failures/success reports in sonar -->
<reportsDirectory>${project.build.directory}/surefire-reports
</reportsDirectory>
<includes>
<include>**/*IT*</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<!-- Prepares a variable, jacoco.agent.ut.arg, that contains the info
to be passed to the JVM hosting the code being tested. -->
<execution>
<id>prepare-ut-agent</id>
<phase>process-test-classes</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<propertyName>jacoco.agent.ut.arg</propertyName>
<append>true</append>
</configuration>
</execution>
<!-- Prepares a variable, jacoco.agent.it.arg, that contains the info
to be passed to the JVM hosting the code being tested. -->
<execution>
<id>prepare-it-agent</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<propertyName>jacoco.agent.it.arg</propertyName>
<append>true</append>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Integraton tests -->
<profile>
<id>run-its</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
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.
Here is the jacoco part from sonar running over my itest module:
[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.
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.