无法为规则'NPathComplexity'找到资源'rulesets / plsql / codesize.xml'

时间:2015-12-15 22:52:14

标签: java eclipse maven pmd

请为以下错误提供一些帮助。

我正在 Maven项目中设置 PMD插件,但是会返回一些我无法确定原因的错误。

我目前正在使用以下设置:

  • Eclipse Mars 4.5.1
  • Maven 3.3.3
  • maven-pmd-plugin 3.5

我通过在工作区根目录中名为ruleset.xml的文件中设置规则来定义我的PMD规则。

<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="pmd-eclipse"
    xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

    <description>PMD Plugin preferences rule set</description>

    <rule ref="rulesets/plsql/codesize.xml/NPathComplexity" />
    <rule ref="rulesets/plsql/codesize.xml/ExcessiveMethodLength" />
    <rule ref="rulesets/plsql/codesize.xml/ExcessiveParameterList" />
    <rule ref="rulesets/plsql/codesize.xml/ExcessiveObjectLength" />
    <rule ref="rulesets/plsql/codesize.xml/ExcessiveTypeLength" />
    <rule ref="rulesets/plsql/codesize.xml/ExcessivePackageBodyLength" />
    <rule ref="rulesets/plsql/codesize.xml/ExcessivePackageSpecificationLength" />
    <rule ref="rulesets/plsql/codesize.xml/CyclomaticComplexity" />
    <rule ref="rulesets/plsql/codesize.xml/TooManyFields" />
    <rule ref="rulesets/plsql/codesize.xml/NcssMethodCount" />
    <rule ref="rulesets/plsql/codesize.xml/NcssObjectCount" />
    <rule ref="rulesets/plsql/codesize.xml/TooManyMethods" />
    ...
</ruleset>

我在pom.xml文件

中配置了PMD插件
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>3.5</version>
    <configuration>
        <linkXRef>true</linkXRef>
        <verbose>true</verbose>
        <failOnViolation>false</failOnViolation>
        <rulesets>
            <ruleset>ruleset.xml</ruleset>
        </rulesets>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>pmd</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>

当我跑pmd:pmd时 我收到以下错误:

  • net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource 'rulesets/plsql/codesize.xml' for rule 'NPathComplexity'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: /Applications/Eclipse JEE.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime_1.6.2.20150902-0001/jars/plexus-classworlds-2.5.2.jar
  • [WARNING] Failure executing PMD: Couldn't find the class Can't find resource 'rulesets/plsql/codesize.xml' for rule 'NPathComplexity'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: /Applications/Eclipse JEE.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime_1.6.2.20150902-0001/jars/plexus-classworlds-2.5.2.jar

控制台日志

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building cadNoticiaMvn1 Maven Webapp 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-pmd-plugin:3.5:pmd (default-cli) @ cadNoticiaMvn1 ---
net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource 'rulesets/plsql/codesize.xml' for rule 'NPathComplexity'.  Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: /Applications/Eclipse JEE.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime_1.6.2.20150902-0001/jars/plexus-classworlds-2.5.2.jar
    at net.sourceforge.pmd.RuleSetReferenceId.getInputStream(RuleSetReferenceId.java:405)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:176)
    at net.sourceforge.pmd.RuleSetFactory.createRule(RuleSetFactory.java:201)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleReferenceNode(RuleSetFactory.java:510)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleNode(RuleSetFactory.java:293)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:242)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:176)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:171)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:135)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:119)
    at net.sourceforge.pmd.RulesetsFactoryUtils.getRuleSets(RulesetsFactoryUtils.java:31)
    at net.sourceforge.pmd.processor.AbstractPMDProcessor.createRuleSets(AbstractPMDProcessor.java:54)
    at net.sourceforge.pmd.processor.MultiThreadProcessor.processFiles(MultiThreadProcessor.java:38)
    at net.sourceforge.pmd.PMD.processFiles(PMD.java:352)
    at org.apache.maven.plugin.pmd.PmdReport.executePmd(PmdReport.java:377)
    at org.apache.maven.plugin.pmd.PmdReport.executePmdWithClassloader(PmdReport.java:280)
    at org.apache.maven.plugin.pmd.PmdReport.canGenerateReport(PmdReport.java:254)
    at org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:119)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    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.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[WARNING] Failure executing PMD: Couldn't find the class Can't find resource 'rulesets/plsql/codesize.xml' for rule 'NPathComplexity'.  Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: /Applications/Eclipse JEE.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime_1.6.2.20150902-0001/jars/plexus-classworlds-2.5.2.jar
java.lang.RuntimeException: Couldn't find the class Can't find resource 'rulesets/plsql/codesize.xml' for rule 'NPathComplexity'.  Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: /Applications/Eclipse JEE.app/Contents/Eclipse/plugins/org.eclipse.m2e.maven.runtime_1.6.2.20150902-0001/jars/plexus-classworlds-2.5.2.jar
    at net.sourceforge.pmd.RuleSetFactory.classNotFoundProblem(RuleSetFactory.java:270)
    at net.sourceforge.pmd.RuleSetFactory.parseRuleSetNode(RuleSetFactory.java:260)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:176)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSet(RuleSetFactory.java:171)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:135)
    at net.sourceforge.pmd.RuleSetFactory.createRuleSets(RuleSetFactory.java:119)
    at net.sourceforge.pmd.RulesetsFactoryUtils.getRuleSets(RulesetsFactoryUtils.java:31)
    at net.sourceforge.pmd.processor.AbstractPMDProcessor.createRuleSets(AbstractPMDProcessor.java:54)
    at net.sourceforge.pmd.processor.MultiThreadProcessor.processFiles(MultiThreadProcessor.java:38)
    at net.sourceforge.pmd.PMD.processFiles(PMD.java:352)
    at org.apache.maven.plugin.pmd.PmdReport.executePmd(PmdReport.java:377)
    at org.apache.maven.plugin.pmd.PmdReport.executePmdWithClassloader(PmdReport.java:280)
    at org.apache.maven.plugin.pmd.PmdReport.canGenerateReport(PmdReport.java:254)
    at org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:119)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    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.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.813 s
[INFO] Finished at: 2015-12-15T19:09:18-03:00
[INFO] Final Memory: 16M/220M
[INFO] ------------------------------------------------------------------------

即使添加plexus-classworlds依赖,它仍然会失败。

1 个答案:

答案 0 :(得分:1)

通过添加这种依赖性可以解决这个问题:

<dependency>
    <groupId>net.sourceforge.pmd</groupId>
    <artifactId>pmd-plsql</artifactId>
    <version>5.4.1</version>
</dependency>

<build>

中的插件上
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>3.5</version>
    <dependencies>
        <dependency>
            <groupId>net.sourceforge.pmd</groupId>
            <artifactId>pmd-plsql</artifactId>
            <version>5.4.1</version>
        </dependency>
    </dependencies>
    <configuration>
        <linkXRef>true</linkXRef>
        <verbose>true</verbose>
        <failOnViolation>false</failOnViolation>
        <rulesets>
            <ruleset>ruleset.xml</ruleset>
        </rulesets>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>pmd</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>