Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PMD+Maven+JAVA Error:: Can't find resource rulesets/comments.xml. Make sure the resource is a valid file or URL or is on the CLASSPATH

Tags:

java

maven

pmd

while adding a custom ruleset of PMD , maven is producing an error -net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource rulesets/comments.xml.Make sure the resource is a valid file or URL or is on the CLASSPATH.

For others rule sets like basic,naming etc its not giving any error.but when i add new ruleset it produced the error. I also tried <rule ref="rulesets/java/comments.xml/CommentRequired"/>but it also giving the same error. comments.xml is already available in pmd-5.0.2.jar file.

My POM.xml

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>pmd</groupId>
        <artifactId>pmd</artifactId>
        <version>5.0.2</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9.1</version>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/site/
                        </outputDirectory>
                        <reportOutputDirectory>${project.reporting.outputDirectory}/site/
                        </reportOutputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>2.7.1</version>
            <configuration>
                <targetjdk>1.6</targetjdk>
                <skip>fasle</skip>
                <failOnViolation>false</failOnViolation>
                <failurePriority>4</failurePriority>
                <verbose>true</verbose>
                <rulesets>
                    <ruleset>src/main/resources/rulesets/MyRuleSet.xml</ruleset>
                </rulesets>
            </configuration>
            <executions>
                <execution>
                    <id>check</id>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
                <execution>
                    <id>cpd-check</id>
                    <goals>
                        <goal>cpd-check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jxr-plugin</artifactId>
            <version>2.3</version>
        </plugin>
    </plugins>
</reporting>

My Custom Ruleset file

<?xml version="1.0"?>
<ruleset>

<rule ref="rulesets/logging-java.xml/SystemPrintln">
    <priority>3</priority>
</rule>
<rule ref="rulesets/naming.xml/VariableNamingConventions">
    <priority>3</priority>
</rule>
<rule ref="rulesets/design.xml/UseSingleton">
    <priority>3</priority>
</rule>
<rule ref="rulesets/controversial.xml/UseConcurrentHashMap">
    <priority>3</priority>
</rule>
<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode">
    <priority>3</priority>
</rule>

<rule ref="rulesets/comments.xml/CommentRequired">
    <priority>3</priority>
</rule>
</ruleset>

Here is my maven stacktrace

    INFO] ------------------------------------------------------------------------
net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource rulesets/comments.xml. Make sure the resource is a valid file or URL or is on the CLASSPATH
    at net.sourceforge.pmd.util.ResourceLoader.loadResourceAsStream(ResourceLoader.java:28)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleReferenceNode(RuleSetFactory.java:365)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:255)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:209)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:157)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:146)
    at org.apache.maven.plugin.pmd.PmdReport.generateReport(PmdReport.java:222)
    at org.apache.maven.plugin.pmd.PmdReport.execute(PmdReport.java:175)
    at org.apache.maven.plugin.pmd.PmdReport.executeReport(PmdReport.java:149)
    at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:190)
    at org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:99)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:364)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:198)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:414)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:357)
like image 827
The PowerHouse Avatar asked Aug 13 '13 07:08

The PowerHouse


2 Answers

The plugin only understands absolute paths. Try an absolute path and it should work. See the documentation.

In order to make it independent from the local file system layout, use ${basedir} to refer to your local path.

like image 178
sorencito Avatar answered Oct 01 '22 03:10

sorencito


it has to be "rulesets/java/comments.xml" instead of "rulesets/comments.xml".

my suspicion is, you picked up "rulesets/comments.xml" from some part of documentation which is out-dated, or was simply not tested before it was published.

like image 43
hoijui Avatar answered Oct 01 '22 02:10

hoijui