PMD Apex 找不到 Windows 规则的资源

PMD Apex Can't find resource for rule on Windows

我正在尝试配置 PMD 以进行代码分析。 我用的是VS Code,已经安装了Java10,下载了几个版本的PMD

我已经为 VS Code 安装了 Apex PMD 扩展并按照它的说明进行了配置。

但是无论我选择哪个版本,都会出现找不到资源的错误。

这是 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

如果我 运行 来自命令行的命令,我会得到类似的输出。 这个错误是针对我的规则集上的每条规则,这没有什么不寻常的,它是扩展附带的默认规则集。

它对我适用于 PMD 6.7.0,但对 5.7.0 无效:

您引用 "category/apex/design.xml/ExcessiveParameterList" 的规则仅在 PMD 6 之后在此路径下可用。在该版本中,我们将规则分类。 使用 PMD 5.7.0 时,您需要使用旧规则集:"rulesets/apex/complexity.xml/ExcessiveParameterList"。 最好使用最新的 PMD 版本。有没有办法配置 Apex PMD 扩展?

另见 https://github.com/pmd/pmd/issues/1344