简体   繁体   English

将自定义Java规则添加到PMD Maven插件

[英]Adding custom java rule to pmd maven plugin

I've wrote a custom rule for pmd (in java). 我已经为pmd(在Java中)编写了自定义规则。 I want this rule to be executed in my project. 我希望在我的项目中执行此规则。 I've added my rule to pmd.xml: 我已将规则添加到pmd.xml中:

<rule name="MyRule"
      message="some message"
      class="MyRule">
    <description>
        some description
    </description>
    <properties>
        <property name="someproperty" value="1" />
    </properties>
    <priority>3</priority>
</rule>

And there the problem appeared. 问题就出现了。 I didn't know where to place the rule definition - MyRule.class. 我不知道规则定义的位置-MyRule.class。 I was trying to add a maven dependency to pmd: 我试图将Maven依赖项添加到Pmd:

<dependency>
    <groupId>pmd.rules</groupId>
    <artifactId>CustomJavaRules</artifactId>
    <version>1.0</version>
</dependency>

where CustomJavaRules is a jar artifact (from local "file://" repo) containing MyRule.class. 其中,CustomJavaRules是一个包含MyRule.class的jar工件(来自本地“ file://”存储库)。 The jar is found and loaded but MyRule.class is still invisible for pmd. 找到并加载了jar,但是MyRule.class对于pmd仍然不可见。

I was trying to place the class in various directories... with poor results. 我试图将类放在各种目录中……结果很差。

Has anyone ever had a similar problem? 有没有人遇到过类似的问题?

Solved: 解决了:

<dependency>
    <groupId>pmd.rules</groupId>
    <artifactId>CustomJavaRules</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>path/to/my/jar/CustomJavaRules.jar</systemPath>
</dependency>

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

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