Checkstyle vs. PMD

前端 未结 17 934
独厮守ぢ
独厮守ぢ 2020-12-12 11:38

We are introducing static analysis tools into the build system for our Java product. We are using Maven2 so Checkstyle and PMD integration come for free. However it looks li

相关标签:
17条回答
  • 2020-12-12 11:54

    I find Checkstyle and PMD are best for enforcing style issues and simple obvious coding bugs. Although I've found that I like using Eclipse and all the warnings it provides better for that purpose. We enforce stuff by using shared preferences and marking them as actual errors. That way, they never get checked in in the first place.

    What I would strongly and enthusiastically recommend is using FindBugs. Because it works at the bytecode level it can check things that are impossible at the source level. While it spits out its fair share of junks, it has found many actual and important bugs in our code.

    0 讨论(0)
  • 2020-12-12 11:55

    I would echo the comment that PMD is the more current product for Java style/convention checking. With respect to FindBugs, many commercial development groups are using Coverity.

    0 讨论(0)
  • 2020-12-12 12:04

    PMD is what I find more people referring to. Checkstyle was what people were referring to 4 years ago but I believe PMD is maintained more continuously and what other IDEs/plugins choose to work with.

    0 讨论(0)
  • 2020-12-12 12:05

    If we choose one, which one should we use and why?

    These tools are not competing but are complementary and should be used simultaneously.

    The convention type (Checkstyle) is the glue that enables people to work together and to free up their creativity instead of spending time and energy at understanding inconsistent code.

    Checkstyle examples:

    • Is there javadoc on public methods ?
    • Is the project following Sun naming conventions ?
    • Is the code written with a consistent format ?

    while PMD reminds you bad practices:

    • Catching an exception without doing anything
    • Having dead code
    • Too many complex methods
    • Direct use of implementations instead of interfaces
    • Implementing the hashcode() method without the not equals(Object object) method

    source: http://www.sonarsource.org/what-makes-checkstyle-pmd-findbugs-and-macker-complementary/

    0 讨论(0)
  • 2020-12-12 12:05

    Take a look at qulice-maven-plugin that combines together Checkstyle, PMD, FindBugs and a few other static analyzers, and pre-configures them. The beauty of this combination is that you don't need to configure them individually in every project:

    <plugin>
      <groupId>com.qulice</groupId>
      <artifactId>qulice-maven-plugin</artifactId>
      <version>0.15</version>
      <executions>
        <execution>
          <goals>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    
    0 讨论(0)
  • 2020-12-12 12:05

    PMD is the finest tool when compare with checkstyles. Checkstyles may not have the capability to analyse the code while PMD offering many features to do so! Offcourse PMD has not released rules for javadoc, comments, indentations and etc. And by the way i am planning to implement these rules.......thanx

    0 讨论(0)
提交回复
热议问题