Update: I've created a Short, Self Contained, Correct Example (SSCCE) here.
I'm currently refactoring a multi-module Apache Maven Proof-of-Concept project and have an issue regarding reporting plugins or the Maven Site generation.
My structure is as follows (list intent == inheritance):
- Company POM
- Company Bills of Material (BoM)
- Aggregator POM
- Code Project Aggregator POM (all source code projects)
- Library JAR
- Application JAR
- Code Coverage Aggregator POM (a non-source code project)
- Code Project Aggregator POM (all source code projects)
The Company POM uses Convention-over-Configuration and does not define any inherited reports, but only "single" reports, e.g:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<report>pmd</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
The top-level "Aggregator POM" does not define any reporting plugins. It's main purpose is to aggregate and allow to separate the "source code" and "non-source code" child projects:
<modules>
<module>pom/code-project-aggregator</module>
<module>pom/code-coverage-aggregator</module>
</modules>
The "Code Project Aggregator POM" defines the aggregate reports with <inherited>false</inherited> and includes all source code projects as modules:
<modules>
<module>../../lib/foo</module>
<module>../../app/bar</module>
</modules>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<reportSets>
<reportSet>
<id>aggregate</id>
<inherited>false</inherited>
<reports>
<report>aggregate-pmd</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
The problem is, that the generated Maven Site for the top-level "Aggregator POM" does not include the reports if calling mvn verify site-deploy.
The reports are generated if mvn verify site-deploy is called for the "Code Project Aggregator POM". But I want to create the top-level site. I don't understand what is happening here: It seems that the aggregate reports are not bound to site if called on the top level.
Two questions:
- Can someone explain this behavior?
- Can someone provide the solution (or guide me into the right direction) that generates and includes the aggregate reports in the child multi-module project if calling
mvn verify site-deployon the top multi-module project?
I've read Building multi-module sites, but couldn't find any mention of issues regarding my approach.
Update #1 2023-06-23: I've looked at the Effective POM of "Code Project Aggregator POM" and the aggregate reports are included there. It seems they are simply not "triggered" if calling mvn verify site-deploy on the parent project.
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.21.0</version>
<reportSets>
<reportSet>
<reports>
<report>pmd</report>
<report>cpd</report>
</reports>
</reportSet>
<reportSet>
<id>aggregate</id>
<reports>
<report>aggregate-pmd</report>
<report>aggregate-cpd</report>
</reports>
<inherited>false</inherited>
</reportSet>
</reportSets>
</plugin>
</reporting>
Update #2 2023-06-23: I was able to fix the PMD aggregate report creation by specifiying a unique <id> to each and every reportSet in the pom.xml files. But: This is not the complete solution, because it did not fix aggregate report creation for other plugins, e.g. Checkstyle, JXR, Surefire, Failsafe and Taglist. I took a closer look at the Effective POM and I am unable to explain this behavior. Both PMD and Checkstyle are registered for the maven-site-plugin below <build>/<plugin> in the execution with the ID default-site as a reportPlugin:
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<reportSets>
<reportSet>
<id>checkstyle-report</id>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
<reportSet>
<id>aggregate-checkstyle-report</id>
<reports>
<report>checkstyle-aggregate</report>
</reports>
</reportSet>
</reportSets>
</reportPlugin>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.21.0</version>
<reportSets>
<reportSet>
<id>pmd-report</id>
<reports>
<report>pmd</report>
<report>cpd</report>
</reports>
</reportSet>
<reportSet>
<id>aggregate-pmd-report</id>
<reports>
<report>aggregate-pmd</report>
<report>aggregate-cpd</report>
</reports>
</reportSet>
</reportSets>
</reportPlugin>
</reportPlugins>
Update 3 2023-06-26: I've created a Short, Self Contained, Correct Example (SSCCE) as a Git repository on GitHub.