Saturday, January 14, 2012

How to add Findbugs and Checkstyle plugins to your maven3 build


Findbugs and Checkstyle are two awesome tools that help to maintain the quality of your code discovering anti patterns or bad smells.Normally we can run those two tools with the help of IDE but there are possibilities that developers may be ignorant about them.So how about adding them to the normal maven build so developers are forced to correct their mistakes. There are different level of sympathetic levels that you can have :) with this integration.You can break the build if you find any Findbug violations and use SVN blame to find who broke the build :D . I am leaving that part to you and introduce basic integration of those essential power tools to Maven build system. I am using maven3 so all assumptions are based on that.

Adding Findbugs

You can find the maven plugin page here.[1]. Under the project Reports–> plugin documentation you can find all the configuration so that you can customize to your own requirements.
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>2.3.3</version>
    <configuration>
        <trace>false</trace>
        <effort>Max</effort>
        <threshold>Low</threshold>
        <xmlOutput>true</xmlOutput>
        <failOnError>false</failOnError>
    </configuration>
    <executions>
        <execution>
            <phase>verify</phase>
            <goals>
                <goal>findbugs</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
This will execute in verify phase before install phase. Since you need to verify your source code before compiling it is the most suitable phase to run.If you search you will find lot more resources how this can be adjusted easily so you can integrate this into report generation and add to the Maven site.
There is another cool hack that i have found in this.[2].This Groovy script will print all the lines and summary to your build log with line number .class name and message.
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<plugin>
      <groupId>org.codehaus.groovy.maven</groupId>
      <artifactId>gmaven-plugin</artifactId>
      <version>1.0</version>
      <executions>
          <execution>
              <phase>install</phase>
              <goals>
                  <goal>execute</goal>
              </goals>
              <configuration>
                  <source>
                      def file = new File("${project.build.directory}/findbugsXml.xml")
                      if (!file.exists()) {
                      log.warn("Findbugs XML report is absent: " + file.getPath())
                      }
                      def xml = new XmlParser().parse(file)
                      def bugs = xml.BugInstance
                      def total = bugs.size()
                      if (total &gt; 0) {
                      log.info("Total bugs: " + total)
                      for (i in 0..total-1) {
                      def bug = bugs[i]
                      log.info("\n"+
                      bug.LongMessage.text()
                      + " " + bug.Class.'@classname'
                      + " " + bug.Class.SourceLine.Message.text()
                      +"\n")
                      }
                      }
                  </source>
              </configuration>
          </execution>
      </executions>
  </plugin>

 Adding Checkstyle

This assumes that you have added a custom checkstyle configuration file(checkstyle.xml) to your projects path directly.If you do not specify a checkstyle configuration file configuration provided by  Sun Microsystems Definition is selected by default.
You can read all the available configuration details from plugin page[3].
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-checkstyle-plugin</artifactId>
     <version>2.8</version>
     <configuration>
         <consoleOutput>true</consoleOutput>
         <configLocation>checkstyle.xml</configLocation>
         <propertyExpansion>basedir=${project.basedir}</propertyExpansion>
     </configuration>
     <executions>
         <execution>
             <phase>verify</phase>
             <goals>
                 <goal>checkstyle</goal>
             </goals>
         </execution>
     </executions>
 </plugin>
 <plugin>
If you have a multi modules insert this under plugin management and add the plugin entry to   child POMs.

16 comments:

  1. do dự mà móc ra một viên Hồi Nguyên đan nhét vào trong miệng, ở trong Cực Viêm địa, phục dụng đến hai viên Hồi Nguyên đan khiến Nhạc Thành tiếc nuối không thôi.

    - Thái Dương Chân Hỏdongtam
    mu private
    tim phong tro
    http://nhatroso.com/
    nhac san cuc manh
    tổng đài tư vấn luật
    http://dichvu.tuvanphapluattructuyen.com/
    văn phòng luật
    tổng đài tư vấn luật
    dịch vụ thành lập công ty
    http://we-cooking.com/
    chém gió
    trung tâm ngoại ngữa, trở về cho ta.

    Thủ ấn của Nhạc Thành ngưng kết, sau khi phục dụng Hồi Nguyên đan, sắc mặt của hắn trở nên hồng hào không ít.

    Ngọn lửa của Nhạc Thành hiện tại không còn là Vô Thượng Chân Hỏa nữa mà chính là Thái Dương Chân Hỏa, một luồng Thái Dương Chân Hỏa này tuy không bằng Thái Dương Chân Hỏa chính thức nhưng uy lực vẫn ở trên Vô Thượng Chân Hỏa.

    Một ngọn lửa vượt không gian bao vây lấy ngọn lửa kia, hai ngọn lửa không ngừng đấu tranh, một lát sau đã trở nên an tĩnh,/

    Bản thể của Thái Dương Chân Hỏa tạo thành ba bàn tay lửa, uy lực khủng bố vô cùng, tuy nhiên hiện tại linh trí của Thái Dương Chân Hỏa đã bị Nhạc Thành luyện hóa, Thái Dương Chân Hỏa hiện tại giống như là một hài nhi mới sinh vậy, cảm nhân thấy khí tức ngọn lửa xong quanh cũng cảm thấy thân cận.

    ReplyDelete
  2. This bit of blog shows commitment of author.
    linkedin

    ReplyDelete
  3. Backlinks are one of the primary components of the search engine algorithms that determine the rank of pages that are the responses to high trust flow blog comments search. So, what are backlinks?

    ReplyDelete
  4. Are you having trouble gaining backlinks niche blog comments your website. Learn some simple link baiting strategies that could help you get one way links without even having to ask for them.

    ReplyDelete
  5. PDF files are being used more and more by both individuals and corporations. As a result of this they are finding their way onto the internet more often. So here are some cool PDF niche backlinkstips and tricks. If implemented correctly these tips and techniques will get your PDF more exposure on the search engines and also use the PDF's to pass link juice to important pages on your sites.

    ReplyDelete
  6. Movie review writing has become quite popular these days. With numerous https://freenetflixacc2019.weebly.com/ review sites out there in the Internet, many people are actually writing genuine and useful movie reviews.

    ReplyDelete
  7. Oh my goodness! a fantastic write-up dude. Thank you Nevertheless My business is experiencing problem with ur rss . Don’t know why Can not subscribe to it. Will there be any person acquiring identical rss issue? Anybody who knows kindly respond. Thnkx Shinexcare.com

    ReplyDelete
  8. Boys love super heroes, cool gadgets, fast cars and space ships, there was never any doubt about that, but that is not the whole story. They also like using their imagination and applying their hunger for adventures. Here we have compiled our list of what are the most popular birthday party themes for boys and although there may not be many surprises, hopefully these results will still give you some good ideas for your birthday party. bachelor parties

    ReplyDelete
  9. Excellently written article, doubts all bloggers offered the same content because you, the internet is a greater place. Please keep it up! sa ra ga ma pa 2016

    ReplyDelete
  10. I believe one of your adverts triggered my web browser to resize, you might want to put that on your blacklist. Naira Marley isheyen mp3 download

    ReplyDelete
  11. I shall explain to you the various methods which you can use to download or watch movies of your taste in a secure and legal manner. Moreover, I shall be highlighting the names of some of the formats in which you can watch them easily and how you can download them on your computer or hard drive. lyrics here

    ReplyDelete
  12. What's the Average Price Range of Entertainment Centers? The price for a home entertainment center can range from under $100 to many thousands of dollars. The price will vary greatly based on the size, material, and design of the piece. Entertainment centers can be as simple as a TV stand with shelves to a complete unit that takes up an entire wall. The price will depend on what type of entertainment center you want. hire MIami strippers

    ReplyDelete
  13. Anyone can learn and do a magic trick, but to take a trick and turn it into an amazing performance is one of the keys to performing great magic. May I suggest most people DO NOT like to feel as though they have been tricked or fooled, instead they like to know they have taken part in good entertainment. Nashville strippers

    ReplyDelete
  14. Anyone can learn and do a magic trick, but to take a trick and turn it into an amazing performance is one of the keys to performing great magic. May I suggest most people DO NOT like to feel as though they have been tricked or fooled, instead they like to know they have taken part in good entertainment. Hamptons strippers

    ReplyDelete
  15. Do you already feel the ice-cold breezy air? Hear "Jingle Bells" over televisions or radios or see bulk shoppers in your favorite malls? Don't ask why, because it already Christmas time! Yes, Christmas is finally here! This is the time when people do Christmas Shopping as part of their preparation for gift giving, Christmas celebration and numerous Christmas parties. rent party characters

    ReplyDelete
  16. Anyone can learn and do a magic trick, but to take a trick and turn it into an amazing performance is one of the keys to performing great magic. May I suggest most people DO NOT like to feel as though they have been tricked or fooled, instead they like to know they have taken part in good entertainment. hire strippers in Blue Ridge

    ReplyDelete