Wednesday, October 22, 2014

How to use snapshot checkstyle version in maven plugin

Base on knowledge from http://maven.apache.org/plugins/maven-checkstyle-plugin/examples/custom-developed-checkstyle.html#Configure_the_Checkstyle_Plugin_to_use_your_custom_checks

you can easily force to maven checkstyle plugin to use custom/snapshot/different version of Checkstyle library.
It is very useful for testing of new Checks and generating HTML report on big sources on checkstyle library that you want and not a default old Checkstyle version that is attached to plugin.

<project>
...
  <build>
    <pluginManagement>
      <plugins>
....
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-checkstyle-plugin</artifactId>
     <version>2.15</version>
     <dependencies>
       <dependency>
   <groupId>com.puppycrawl.tools</groupId>
         <artifactId>checkstyle</artifactId>
          <version>6.5-SNAPSHOT</version>
       </dependency>
     </dependencies>
        <configuration>
          <configLocation>my_checkstyle.xml</configLocation>
          <enableFilesSummary>false</enableFilesSummary>
        </configuration>
   </plugin>        
.....
      </plugins>
    </pluginManagement>
  </build>
......
  <reporting>
    <plugins>
     <!-- that plugin is required to link violation with source code, without that plugin report is useless and hard to use -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
        <version>2.5</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.15</version>
<!-- Specifying configuration here will take effect on the execution of "mvn site",
          but will not take effect on the execution of "mvn checkstyle:checkstyle"  -->
<configuration>
           <configLocation>checkstyle.xml</configLocation>
            <failOnViolation>false</failOnViolation>
            <enableFilesSummary>false</enableFilesSummary>
</configuration>
      </plugin>
    </plugins>
  </reporting>
....
</project>

Build HTML report by "mvn site" command, or "mvn checkstyle:checkstyle".

to have different HTML reports (for each tested Check) over the same sources - just save index.html as index-MyCheck.html, and do report generation for each Check separately.

No comments:

Post a Comment