I am trying to do a jacoco-aggregate to send it to sonarqube according to this post: https://community.sonarsource.com/t/coverage-test-data-importing-jacoco-coverage-report-in-xml-format/12151
Apparently it is needed to use the xml format aggregated now because SonarQube does not use the exec file anymore according to this warning on SonarQube (But I can't see where it is officially stated besides a forum post and it was working some months ago on my project with exec files)
My pom architecture is like this:
-root
--child1
-- common
-- coverage
-- etc
My root pom look like this (only the interesting part about jacoco)
<modelVersion>4.0.0</modelVersion>
<groupId>com.toto.example</groupId>
<artifactId>root</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
My child1 and common pom look like this
<modelVersion>4.0.0</modelVersion>
<groupId>com.toto.example</groupId>
<artifactId>child1</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<!-- need to add this in order for the correct to be passed, and create the jacoco.exec -->
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
My coverage pom look like this:
<modelVersion>4.0.0</modelVersion>
<groupId>com.toto.example</groupId>
<artifactId>coverage</artifactId>
<version>1.0.0</version>
<!-- Used to determine which module should be aggregated -->
<dependencies>
<dependency>
<groupId>com.toto.example</groupId>
<artifactId>child1</artifactId>
<version1.0.0</version>
</dependency>
<dependency>
<groupId>com.toto.example</groupId>
<artifactId>common</artifactId>
<version1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I run a mvn clean install I see the following result in folders:
- root
-- child1
----target
------jacoco.exec
--common
----target
------jacoco.exec
--coverage
--- target
-----site
-------jacoco-aggregate
---------jacoco.xml (The famous file I need to pass to sonarqube)
I do a mvn verify on the root parent and in debug mode I see that I pass in jacoco-aggregate method in the createRepport. However the result is empty and I don't understand why. If I open the index.html in the coverage part, I get the following result:
There is no coverage added and I don't understand why, the jacoco.exec have info in it so I don't understand why it's not aggregated correctly in the jacoco-aggregate. I make sure to be as close as the jacoco-example at: https://github.com/jacoco/jacoco/tree/master/jacoco-maven-plugin.test/it/it-report-aggregate and when I try this test I can see the following result:
But I can't get the same result on my end