Generating source references with the Maven JXR plugin

You may have observed the following warnings when running the PMD or Checkstyle plugin:

[INFO] --- maven-pmd-plugin:3.2:pmd (default-cli) @ project-with-violations ---
[WARNING] Unable to locate Source XRef to link to – DISABLED
[INFO] --- maven-checkstyle-plugin:2.13:checkstyle (default-cli) @ project-with-violations ---
[INFO]
[INFO] There are 36 checkstyle errors.
[WARNING] Unable to locate Source XRef to link to – DISABLED

The plugins attempt to link the violation to the specific lines in the cross-reference of the source. As they are unable to find this cross-reference, they display the warning.

To generate this cross-reference, we need to use the Maven JXR plugin.

How to do it...

Use the following steps to generate source references with the Maven JXR plugin:

  1. Open the project for which you want to run the cross-reference.
  2. Run the following Maven command:
    mvn jxr:jxr
    
  3. Observe the output:
    [INFO]
    [INFO] --- maven-jxr-plugin:2.5:jxr (default-cli) @ project-with-violations ---
    [INFO] ------------------------------------------------------------------------
    
  4. Browse the target/site folder.
    How to do it...
  5. Open the contents of the xref folder in the browser:
    How to do it...

How it works...

When the jxr goal of the Maven JXR plugin is run, it generates a cross-reference of all the source files of the project. The format is similar to Javadoc, but on clicking on the class, you get to see the source code with the line numbers:

How it works...

There's more...

Once the cross-reference exists, code quality tools, such as PMD and Checkstyle, link to this reference automatically by using the following steps:

  1. Run the following Maven command:
    mvn jxr:jxr checkstyle:checkstyle
    
  2. Open the Checkstyle report in the browser:
    There's more...

You can now see the line numbers against each of the violations, with the link to the line number in the cross-referenced source code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.178.181