Friday, February 3, 2012

Maven Clirr plugin example : maven3 plugins

maven clirr plugin from org.codehaus.mojo:-

Maven Clirr plugin is used to give the report of your current project by comparing with another same old project. Basically, if we configured this plugin to your project, it checks your project jar with an older version jar that is configured in pom.xml to compare. This plugin is to compare the source code as well as jar comparisons for incompatible issues to find in the early stage of any module before releasing the module.

Why maven clirr is important before maven release:- 

 if you are releasing any maven module, that module should be well worked with backward compatible with modules that use it. Once the module is released. that module is used by different developers of different teams, if you find any issues after release, then we have to fix that issue rereleasing is the tedious task. To avoid this, It is always a good idea to use clirr plugin execution checks against the previous version to verify compatibility before releasing any your project module. This will specify any binary compatible issues with the previous code.
Adding this plugin is straightforward in pom.xml. we have to add this plugin element in the pluginManagement section of your project's pom.xml. This is the same process for any new plugin to add to your project.

<pluginmanagement>
  <plugins>
    <plugin>
         <groupid>org.codehaus.mojo</groupid>
         <artifactid>clirr-maven-plugin</artifactid>
     </plugin>
  </plugins>
</pluginmanagement>
org.codehaus.mojo is providing the plugin to the maven repository. Once this plugin is configured,clirr-maven-plugin is downloaded into your local repository.

Maven Clirr plugin reporting:-

Once you configured the clirr plugin, you have to generate the reports for the compatible issues.
This report shows the list of all errors and warnings with detailed messages messages
<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 need to check with oldest project jar (1.1), then you have to define that version in a comparisonVersion element in the reporting section.

How to generate the Clirr report?

Once plugin configuration and reporting configuration is configured in pom.xml, we have to run maven site command to generate the report.
maven site
By running this on the command prompt, This will generate a clirr HTML report under the target/site directory with clirr-report.html
Alternatively, you can also run mvn clirr:clirr to generate the report.
mvn clirr:clirr
Hope you understand the basics of maven clirr plugin with examples.

Please feel to share your comments on this.