Error PMD + Maven + JAVA :: Cannot find the resource rule set /comments.xml. Verify that the resource is a valid file or URL or is on CLASSPATH

when adding a custom PMD rule set, maven generates 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 other rule sets, such as basic, naming, etc., it gives no error. But when I add a new set of rules, it throws an error. I also tried <rule ref="rulesets/java/comments.xml/CommentRequired"/> but also gave the same error. comments.xml is already available in the 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 rules 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) 
+4
source share
2 answers

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

To make it independent of the local file system location, use ${basedir} to link to your local path.

+2
source

it should be "rulesets / java / comments.xml" instead of "rulesets / comments.xml".

My suspicion is that you selected "rulesets / comments.xml" from some part of the documentation that was outdated or simply not tested before being published.

+1
source

Source: https://habr.com/ru/post/1496726/


All Articles