简体   繁体   中英

Adding custom java rule to pmd maven plugin

I've wrote a custom rule for pmd (in java). I want this rule to be executed in my project. I've added my rule to 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. I was trying to add a maven dependency to 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. The jar is found and loaded but MyRule.class is still invisible for 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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