简体   繁体   English

使用Sonar规则集在本地运行Maven PMD

[英]Running Maven PMD locally using Sonar ruleset

I'm attempting to run pmd locally using Maven. 我正在尝试使用Maven在本地运行pmd。 In project I run 在项目中我运行

mvn jxr:jxr pmd:pmd

but receive error : 但收到错误:

net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource 'rulesets/basic.xml' for rule 'UnusedNullCheckInEquals'.  Make sure the resource is a valid file or URL and is on the CLASSPATH

Here is a snippet of the rules file which was exported : 这是已导出的rules文件的片段:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
  <rule ref="rulesets/basic.xml/UnusedNullCheckInEquals">
    <priority>3</priority>
  </rule>
</ruleset>

I've updated pom file to reference custom ruleset : 我已经更新pom文件以引用自定义规则集:

          <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>3.2</version>
        <configuration>
            <linkXref>true</linkXref>
            <rulesets>
                <ruleset>c:\\pmd\\export.xml</ruleset>
            </rulesets>

        </configuration>
    </plugin>

To export the ruleset so can run pmd locally using Maven is it required to export this file (basic.xml) & all other xml files which together comprise the "Sonar Way" quality profile ? 要导出规则集,以便可以使用Maven在本地运行pmd,是否需要导出此文件(basic.xml)和所有其他包含“声纳方式”质量配置文件的xml文件? If so where can these files be accessed on Sonar ? 如果可以,在Sonar上哪里可以访问这些文件?

You can access thru "Quality Profiles > Sonar Way > Permalinks > PMD", although, I think "Sonar Way" pmd rules are empty by default (all rules disabled). 您可以通过“质量配置文件>声纳方式>固定链接> PMD”访问,尽管我认为“声纳方式” pmd规则默认为空(所有规则均已禁用)。

Also, have in mind that version 3.2 of maven-pmd-plugin looks for rules not in rulesets but in rulesets/java , so you might have to replace that path in the exported file (at least the file that you get with Sonar 4.2). 此外,在记住的3.2版本maven-pmd-plugin查找规则不是rulesets ,但在rulesets/java ,所以你可能不得不更换在导出的文件(你有声纳4.2至少拿到文件),该路径。

Finally, I would recommend not using a hardcoded path to reference the ruleset file, use something like: 最后,我建议不要使用硬编码路径来引用规则集文件,而应使用类似以下内容的方法:

<ruleset>${project.basedir}/rules/pmd-rules.xml</ruleset>

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM