Search code examples
code-analysisapexpmdstatic-code-analysis

PMD Apex Can't find resource for rule on Windows


I'm trying to configure PMD for code analysis. I'm using VS Code, already installed Java 10, downloaded several versions of PMD enter image description here

I've installed the Apex PMD extension for VS Code and configured it as per it's instructions.

But keep getting the can't find resource error no matter which version I choose.

This is part of the output from VS Code

PMD Command: java -cp "C:\Code\pmd-bin-5.7.0\lib*" net.sourceforge.pmd.PMD -d "c:\Code\Lightning\src\classes\AccountController.cls" -f csv -R "C:\Code\ruleset\apex_default.xml" error:Error: Command failed: java -cp "C:\Code\pmd-bin-5.7.0\lib*" net.sourceforge.pmd.PMD -d "c:\Code\Lightning\src\classes\AccountController.cls" -f csv -R "C:\Code\ruleset\apex_default.xml" Sep 12, 2018 2:35:20 PM net.sourceforge.pmd.RulesetsFactoryUtils getRuleSets SEVERE: Ruleset not found net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource 'category/apex/design.xml' for rule 'ExcessiveParameterList'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: C:\Code\pmd-bin-5.7.0\lib\antlr-runtime-3.5.2.jar;C:\Code\pmd-bin-5.7.0\lib\antlr4-runtime-4.5.2-1.jar;C:\Code\pmd-bin-5.7.0\lib\asm-5.0.4.jar;C:\Code\pmd-bin-5.7.0\lib\commons-io-2.4.jar;C:\Code\pmd-bin-5.7.0\lib\commons-lang3-3.4.jar;C:\Code\pmd-bin-5.7.0\lib\groovy-2.4.7.jar;C:\Code\pmd-bin-5.7.0\lib\gson-2.5.jar;C:\Code\pmd-bin-5.7.0\lib\javacc-5.0.jar;C:\Code\pmd-bin-5.7.0\lib\jaxen-1.1.6.jar;C:\Code\pmd-bin-5.7.0\lib\jcommander-1.48.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-apex-5.7.0-apex-jorje-shaded.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-apex-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-core-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-cpp-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-cs-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-fortran-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-go-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-groovy-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-java-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-javascript-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-jsp-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-matlab-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-objectivec-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-perl-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-php-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-plsql-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-python-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-ruby-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-scala-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-swift-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-ui-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-visualforce-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-vm-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\pmd-xml-5.7.0.jar;C:\Code\pmd-bin-5.7.0\lib\rhino-1.7.7.jar;C:\Code\pmd-bin-5.7.0\lib\saxon-9.1.0.8-dom.jar;C:\Code\pmd-bin-5.7.0\lib\saxon-9.1.0.8.jar;C:\Code\pmd-bin-5.7.0\lib\scala-compiler-2.10.4.jar;C:\Code\pmd-bin-5.7.0\lib\scala-library-2.10.4.jar;C:\Code\pmd-bin-5.7.0\lib\scala-reflect-2.10.4.jar

If i run the command from command line I get a similar output. This error is for every rule I have on my ruleset which is nothing out of the ordinary, it's the default ruleset that comes with the extension.


Solution

  • It works for me with PMD 6.7.0 and fails with 5.7.0:

    The rule, you reference "category/apex/design.xml/ExcessiveParameterList" is available under this path only since PMD 6. With that version, we put the rules into categories. When using PMD 5.7.0, you'll need to use the old ruleset: "rulesets/apex/complexity.xml/ExcessiveParameterList". It's probably better to use the latest PMD version. Is there a way, to configure the Apex PMD extension?

    See also https://github.com/pmd/pmd/issues/1344