在添加 PMD 的自定义规则集时,maven 产生错误 - 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
.
对于其他规则集,如基本、命名等,它不会给出任何错误。但是当我添加新规则集时,它会产生错误。我也尝试过<rule ref="rulesets/java/comments.xml/CommentRequired"/>
,但它也给出了同样的错误。comments.xml 已在 pmd-5.0.2.jar 文件中可用。
我的 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>
我的自定义规则集文件
<?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>
这是我的 Maven 堆栈跟踪
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)