PMD+Maven+JAVA 错误:找不到资源规则集/注释.xml。确保资源是有效的文件或 URL 或位于类路径上



在添加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.02.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>

这是我的专业堆叠

    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)

插件只了解绝对路径。尝试一条绝对路径,它应该会起作用。请参阅文档。

为了使其独立于本地文件系统布局,请使用${basedir}引用本地路径。

它必须是"rulesets/java/comments.xml",而不是"rulesets/comments.xml"。

我的怀疑是,您从文档中的某个过时的部分获取了"rulesets/comments.xml",或者在发布之前根本没有经过测试。

最新更新