简体   繁体   中英

Adding a ruleset to PMD?

I'm trying to add a JSP ruleset to an existing Maven build using PMD. Unfortunately, it seems like no matter what I do I get an error. If I add the reference to our existing ruleset:

<rule ref="rulesets/jsp/basic.xml/NoUnsanitizedJSPExpression"  /> 

I get this message (linebreaks added for readability:

Execution DRY of goal org.apache.maven.plugins:maven-pmd-plugin:2.7.1:pmd failed: 
Couldn't find that class Can't find resource rulesets/jsp/basic.xml. 
Make sure the resource is a valid file or URL or is on the CLASSPATH -> [Help 1]

I've consulted this question and tried various permutations of leading slashes:

<rule ref="/rulesets/jsp/basic.xml/NoUnsanitizedJSPExpression"  />

but I still get the error message referenced above.

I've tried adding the ruleset to the Maven plugin (second ruleset) :

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <configuration>
            <rulesets>
                <ruleset>${project.basedir}/src/main/resources/properties/pmd_workspace.xml</ruleset>
                <ruleset>rulesets/jsp/basic.xml</ruleset>
            </rulesets>
        </configuration>
        <executions>
            <execution>
                <id>DRY</id>
                <phase>test</phase>
                <goals>
                    <goal>cpd</goal>
                    <goal>pmd</goal>
                </goals>
            </execution>
        </executions>
    </plugin>  

but that simply gives me this error:

An error has occurred in PMD Report report generation. Could not find resource 'rulesets/jsp/basic.xml'. -> [Help 1]

I've looked at the documentation for PMD and for the Maven PMD plugin but had no luck. Can anyone help or point me to a tutorial?

This turned out be because I was using an old version of the Maven PMD plugin. The Maven plugin pulls in PMD by itself, which is convenient, but doesn't give you any control over what version it pulls in.

The version I was using, 2.7.1, pulled in PMD version 4.3, which did not have the rule I was trying to include. Therefore, it (correctly) stated that it couldn't find that rule.

The current version of the Maven PMD plugin, 3.3, pulls in PMD version 5.2.1, which does include the NoUnsanitizedJSPExpression JSP-checking rule.

Once I updated the maven PMD plugin to version 3.3, everything worked:

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-pmd-plugin</artifactId>
                        <version>3.3</version>
                        <configuration>
                            <rulesets>
                                <ruleset>${project.basedir}/src/main/resources/properties/pmd_workspace.xml</ruleset>
                            </rulesets>
                        </configuration>
                    </plugin>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM