Maven Clirr plugin example: maven3 plugins tutorials

This tutorial covers the Clirr Maven Plugin, providing a guide on its configuration and report generation with examples.

What is the Maven Clirr Plugin?

The Maven Clirr plugin is employed to analyze and report on your current project by comparing it with an older version of the same project.

When configured in your project, this plugin checks your project’s JAR with an older version’s JAR, as specified in the pom.xml for comparison.

The plugin conducts source code and JAR comparisons, helping to identify incompatible issues in the early stages of any module before its release

Why maven clirr is important before maven release

When releasing a Maven module, the module must work well with backward compatibility, especially with other modules that depend on it.

After a module is released, it is used by developers from different teams. If issues are discovered post-release, fixing and re-releasing can be a tedious task.

To preemptively avoid this scenario, it is advisable to utilize the Maven Clirr plugin execution for compatibility checks against the previous version before releasing any modules in your project.

This process helps identify and address any potential binary compatibility issues with the previous code.

Adding this plugin is straightforward in the pom.xml. Simply include the plugin element in the pluginManagement section of your project’s pom.xml. This follows the same process as adding any new plugin to your project.

<pluginmanagement>
  <plugins>
    <plugin>
         <groupid>org.codehaus.mojo</groupid>
         <artifactid>clirr-maven-plugin</artifactid>
     </plugin>
  </plugins>
</pluginmanagement>

The plugin is provided by org.codehaus.mojo and is available in the Maven Repository. Upon configuring this plugin, the clirr-maven-plugin is automatically downloaded into your local repository.

Maven Clirr plugin reporting

After configuring the Clirr plugin, you need to generate reports for compatibility issues. This report provides a comprehensive list of all errors and warnings, along with detailed messages.

The plugin is configured in the reporting section of the pom.xml

<reporting>
<plugins>
    <plugin>
      <groupid>org.codehaus.mojo</groupid>
      <artifactid>clirr-maven-plugin</artifactid>
      <version>2.2.2</version>
      <configuration>
        <comparisonversion>1.1</comparisonversion>
      </configuration>
  </plugin>
 </plugins>
</reporting>

If your current project version is 1.2, you should compare it with the older project JAR (1.1). To do this, you need to define that version in a comparisonVersion element within the reporting section.

How to generate the Clirr report?

After configuring both the plugin and reporting sections in the pom.xml, you need to execute the maven site command to generate the report

maven site

Executing this on the maven commands prompt will generate a Clirr HTML report. You can find the report under the target/site folder with the filename clirr-report.html.

Alternatively, you can run mvn clirr:clirr to directly generate the report.

mvn clirr:clirr

Hope you understand the basics of the maven clirr plugin with examples.