pradeep cs
pradeep cs

Reputation: 523

PMD rule set is not getting downloaded/updated through MAVEN

I tried to integrate PMD in one of my project (I am using MAVEN Build tool) When I try to integrate, I can see XML configuration files are mandatory. I have tried to download PMD plugin - I expected global ruleset files might be available in PMD plug in, but they are not. I used below link: https://sourceforge.net/projects/pmd/?source=typ_redirect

After googling, I have seen one link to get ruleset http://grepcode.com/file/repo1.maven.org/maven2/pmd/pmd/4.3 I cant download all XML files.

Is there any way to download/update through build or can we get all XML files in one location anywhere? I tried my level best to search in google and couldn't figure it out.

I attached pom.xml here. Can you please let me know how to add my ruleset automatically whenever PMD updated automatically?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.scm</groupId>
  <artifactId>parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>SCM-PRODUCT</name>
  <description>SCM Product for learning purpose</description>
  <properties>
    <java.version>1.7</java.version>
    <hibernate.validator.version>5.2.4.Final</hibernate.validator.version>
    <javax.el-api.version>2.2.4</javax.el-api.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <checkstyle-config-url>
      D:/rules/checkstyle/2.0/checkstyle-2.0.xml
   </checkstyle-config-url>
    <checkstyle.version>6.18</checkstyle.version>

    <log4j.version>1.2.17</log4j.version>
    <!-- TEST CASES RELATED BEGINS-->

    <junit.version>4.12</junit.version>     

    <!-- TEST CASES RELATED ENDS HERE-->

    <!-- STATIC CODE ANALYSIS PROPERTIES -->
    <findbugs.plugin.version>3.0.3</findbugs.plugin.version> <!-- Reports on common code mistakes and pitfalls -->
    <checkstyle.plugin.version>5.0</checkstyle.plugin.version> <!-- Checks Code Style for Developers -->
    <pmd.plugin.version>3.6</pmd.plugin.version> <!-- Source Code Analyzer -->

    <doxia.module.markdown.version>1.3</doxia.module.markdown.version>
    <javadoc.plugin>2.8.1</javadoc.plugin> <!-- Generates JavaDoc -->
    <jxr.plugin>2.3</jxr.plugin> <!-- Cross reference report of project source code -->

    <!-- REPORTING TOOL PROPERTIES -->
    <project.info.reports.plugin>2.4</project.info.reports.plugin> <!-- A plethora of miscellaneous report: info, ci, dependencies, scm, plugins, etc. -->
    <site.plugin>3.1</site.plugin>
    <sonar.plugin>3.2-RC3</sonar.plugin> <!-- Analysis and metrics on code over time -->
    <surefire.plugin>2.12</surefire.plugin> <!-- Reports Test Results -->
    <taglist.plugin>2.4</taglist.plugin> <!-- Reports on Tags such as @todo and //TODO -->
    <versions.plugin>1.3.1</versions.plugin>
    <maven-compiler-plugin>3.1</maven-compiler-plugin>
    <cobertura.plugin>2.5.1</cobertura.plugin> <!-- Reports Test Coverage -->

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>
  <modules>
    <module>services</module>
    <module>presentation</module>
    <module>service_validator</module>
    <module>jsonvo</module>
  </modules>
  <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.validator.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>${javax.el-api.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- http://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/net.sourceforge.pmd/pmd -->
        <dependency>
            <groupId>net.sourceforge.pmd</groupId>
            <artifactId>pmd</artifactId>
            <version>5.4.2</version>
        </dependency>
    </dependencies>
  </dependencyManagement>
  <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugin</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <includeTests>true</includeTests>
                    <rulesets>
                        <ruleset>${checkstyle-config-url}</ruleset>
                    </rulesets>
                    <minimumTokens>100</minimumTokens>
                    <targetJdk>${java.version}</targetJdk>
                    <failOnViolation>true</failOnViolation>
                </configuration>
                <executions>
                    <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
                </executions>      
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>${pmd.plugin.version}</version>
                <configuration>
                    <targetJdk>${java.version}</targetJdk>
                    <minimumTokens>20</minimumTokens>
                    <skipEmptyReport>false</skipEmptyReport>
                    <failOnViolation>true</failOnViolation>
                    <printFailingErrors>true</printFailingErrors>
                    <!--<includeTests>true</includeTests>-->
                    <rulesets>
                        <ruleset>${pom.basedir}/pmd-rulesets.xml</ruleset>
                    </rulesets>
                    <!-- 
                    <excludeRoots>
                        <excludeRoot>target/generated-sources/antlr</excludeRoot>
                        <excludeRoot>target/generated-sources/antlr/com/puppycrawl/tools/checkstyle/grammars/javadoc</excludeRoot>
                    </excludeRoots>
                     -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>pmd</goal>
                            <goal>cpd</goal>
                            <goal>cpd-check</goal>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>${findbugs.plugin.version}</version>
                <configuration>
                    <effort>Max</effort>
                    <threshold>Low</threshold>
                    <excludeFilterFile>config/findbugs-exclude.xml</excludeFilterFile>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>

    </plugins>
  </build>
</project> 

Upvotes: 0

Views: 1349

Answers (2)

adangel
adangel

Reputation: 1910

You are using version 3.6 of the maven-pmd-plugin. There is a default value for the rulesets - it's java-basic, java-imports and java-unusedcode. See the maven-pmd-plugin documentation.

If you want to start with these rulesets, you can omit the rulesets tag altogether, as krzyk mentioned.

Maven Plugin 3.6 uses PMD 5.3.5 - so downloading rulesets for PMD 4.3 will not work.

But, you don't need to download the rulesets. You can create your own custom ruleset, which references the rules you want to have checked in your code. And this would be your file pmd-rulesets.xml.

Is there any way to download/update through build or can we get all XML files in one location anywhere?

There is no such a ruleset. Enabling all rules PMD provides, doesn't make sense, as some rules contradict each other. Please read "Best Practices": Choose the rules that are right for you.

Can you please let me know how to add my ruleset automatically whenever PMD updated automatically?

You don't need to add your ruleset - you are using it already. However, if a new PMD version has new rules, you won't necessarily have these new rules activated. So, you might want to read the release notes of PMD and checkout if there are new interesting rules. Then you can reference the new rules in your ruleset file.

For the java language, you can see the available rules in the Rulesets index.

Upvotes: 0

Krzysztof Krasoń
Krzysztof Krasoń

Reputation: 27496

If you don't need to use your custom pmd rulesets you can omit the rulesets tag altogether.

If you want to use only some of pmd rulesets you can use predefined ones:

      <rulesets>
        <ruleset>/rulesets/java/braces.xml</ruleset>
        <ruleset>/rulesets/java/naming.xml</ruleset>
      </rulesets>

Upvotes: 1

Related Questions