Table of Contents
- Table of Contents
- Introduction
- Plugin Management – Controlling the Version
- Reporting Plugin – Updating the Site
- Generating the Site
- Viewing the New Reports
- Summary
Introduction
Other project reports, such as static code analysis Maven plugin’s reports, will need to reference the source code in their own reports. This is where the Maven Java Cross Referencing (JXR) plugin is helpful. It generates a set of main/test source code reports for the Maven site that can either be viewed stand-alone or referenced by other Maven site reports.
Plugin Management – Controlling the Version
In the pom.xml file’s project/build/pluginManagement/plugins section, add an entry to control the expected version for this plugin.
Note: This is more helpful in a parent or bill of materials (BOM) pom.xml file which is either referenced or imported into other Maven sub-modules, but we will include this step in our Java101 file, for easy reference.
<plugin>
<!-- Source code cross-reference pages, also used for other reports. -->
<!-- https://maven.apache.org/jxr/maven-jxr-plugin/usage.html -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.3.0</version>
</plugin>
Reporting Plugin – Updating the Site
By adding this plugin (without the version element, since that is already defined in the plugin management section) to the project/reporting/plugins section of the build, we can add the related source and test source reports to the Maven build’s site.
<plugin>
<!-- Source code cross-reference pages, also used for other reports. -->
<!-- https://maven.apache.org/jxr/maven-jxr-plugin/usage.html -->
<!-- The version is defined in the Build Plugin Management section. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
Generating the Site
By running the Maven command to generate the site, we can generate these new reports.
mvn site
Afterward, we can confirm the new reports are generated at:
- target/site/xref/index.html
- target/site/xref-test/index.html
Viewing the New Reports
On each of the new reports listed above, we can Right Click -> Open In -> Browser -> Choose your favorite Browser to view the report contents. Within the index.html page, we should be able to drill into packages and/or classes by clicking on the related link until we see source code information.
If you are already viewing another page of the Maven site, they are also present in the Project Documentation (navigation) section on various Maven site reports under:
- Project Documentation
- Project Reports
- Source Xref
- Test Source Xref
- Project Reports
Summary
Maven builds can generate main and test source code cross reference reports that can either be used directly, or referenced by other build reports that reference the source code, such as static code analysis reports. These reports are helpful when another report doesn’t output the source code directly, but instead wants to create deep links to the source code displayed in another report.

Leave a comment