As described here:
https://github.com/jacoco/jacoco/pull/388#issuecomment-211578936
I understood that I should have a separate aggregator pom and inheritance pom. My project layout is now as follows:
aggregator pom
|- parent pom
|- module a
|- module b
In the parent pom, I've configured the Jacoco agent for coverage data collection, and I've configured a per-module report:
<reportSets>
<reportSet>
<id>default</id>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
This works as expected, module a and module b each get a coverage report for only this module.
In the aggregator pom, I've configured an aggregated report:
<reportSets>
<reportSet>
<id>aggregate</id>
<reports>
<report>report-aggregate</report>
</reports>
</reportSet>
</reportSets>
However, this results in an empty report. It seems that the plugin doesn't know that it should collect the execution data files from module a and module b. How should I tell it where to find all execution data files? Using dependencies is probably not the way to go, since the whole idea is that the aggregator pom has no dependencies, only the parent pom is part of the dependency cycle!
Regards,
Michel.
The whole idea of the aggregator project is that it builds *after* the modules. This is also how it seems to work: The build starts with the parent pom, then module a and b get built, and lastly the aggregator pom is built. So I'm not sure that your idea will solve the issue. Also, before I separated the aggregator and parent pom, I tried moving all the site stuff in a separate module (something akin to the report module in your example), that didn't work. The (huge) downside to this approach is also that I have to specify the dependencies twice. So, again, why can't it work from the aggregator module? Other aggregate reports work fine, and the execution order is fine as well. Especially since I usually do a mvn install first, and only then I do a mvn site. This means that even if the order is wrong, execution data is available when I run mvn site!
Regards,
Michel.
Intuitively, I would have expected the mechanism to work like that. Instead, I think you're emphasizing that the general Maven concept of aggregator POMs works differently and is not capable of realizing that "ideal" scenario. Seems that the Maven aggregator POM is just good for listing and running a couple of modules with one call and not for final result collection... Am I right so far?
So how would you configure a separate report module like you mentioned? The most important piece of information is obviously that the report-aggregate goal does not use the <modules> list to gather coverage information from but rather the <dependencies> list, right? So basically we would set up a module with lots of "fake" dependencies?
That's what I thought would work at first ("report-aggregate" and "aggregation POM" sounds like it just fits together... maybe the jacoco-goal should better be "report-collection" or something to avoid potential mixup...) but is obviously wrong:
<project ...>
<groupId>org.acme</groupId>
<artifactId>report-module</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>../module-a</module>
<module>../module-b</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site-aggregate</id>
<phase>prepare-package</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<project ...>
<groupId>org.acme</groupId>
<artifactId>report-module</artifactId>
<version>1.0</version>
<packaging>jar</packaging> <!-- instead of the aggregate 'pom' a default module? -->
<dependencies>
<dependency>
<groupId>org.acme</groupId>
<artifactId>module-a</artifactId>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>module-b</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site-aggregate</id>
<phase>prepare-package</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Your observation about report-aggregate is also correct, see goal
documentation for details:
http://www.eclemma.org/jacoco/trunk/doc/report-aggregate-mojo.html
The report is created from all modules this project depends on.
Our integration tests contain a example project:
https://github.com/jacoco/jacoco/tree/master/jacoco-maven-plugin.test/it/it-report-aggregate