我有一个自定义规则集定义,它引用捆绑规则集中的一堆规则。但是,我在解决 maven pmd 插件中的这些捆绑规则集时遇到了问题。这是一个相关的问题,该问题有一个快速的'n'dirty 解决方案。但是,我想知道这个问题是否有一个干净的解决方案(因为我认为这是一个相当常见的用例,或者?)。在下文中,我将描述迄今为止我尝试过的尝试:
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-pmd-plugin.version}</version>
<configuration>
<linkXref>true</linkXref>
<rulesets>
<ruleset>my_pmd_ruleset.xml</ruleset>
</rulesets>
<failsOnError>false</failsOnError>
<source>${java.source.version}</source>
<target>${java.source.version}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
我在父 pom 的构建/插件管理部分以及报告部分中使用我的自定义规则集(和 Java 1.6)定义了 maven pmd 插件(版本 3.0.1)。我收到以下许多警告:
[WARNING] Failure executing PMD: Unable to find referenced rule UnusedModifier; perhaps the rule name is mispelled?
我试图参考所有使用的捆绑规则集:
<build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>${maven-pmd-plugin.version}</version> <configuration> <linkXref>true</linkXref> <rulesets> <ruleset>rulesets/java/coupling.xml</ruleset> <ruleset>rulesets/java/design.xml</ruleset> <ruleset>rulesets/java/controversial.xml</ruleset> <ruleset>rulesets/java/codesize.xml</ruleset> <ruleset>rulesets/java/clone.xml</ruleset> <ruleset>rulesets/java/braces.xml</ruleset> <ruleset>rulesets/java/basic.xml</ruleset> <ruleset>rulesets/java/finalizers.xml</ruleset> <ruleset>rulesets/java/imports.xml</ruleset> <ruleset>rulesets/java/unit.xml</ruleset> <ruleset>rulesets/java/logging-jakarta-commons.xml</ruleset> <ruleset>rulesets/java/logging-java.xml</ruleset> <ruleset>rulesets/java/migrating.xml</ruleset> <ruleset>rulesets/java/naming.xml</ruleset> <ruleset>rulesets/java/optimizations.xml</ruleset> <ruleset>rulesets/java/strictexception.xml</ruleset> <ruleset>rulesets/java/strings.xml</ruleset> <ruleset>rulesets/java/sunsecure.xml</ruleset> <ruleset>rulesets/java/typeresolution.xml</ruleset> <ruleset>rulesets/java/unusedcode.xml</ruleset> <ruleset>my_pmd_ruleset.xml</ruleset> </rulesets> <failsOnError>false</failsOnError> <source>${java.source.version}</source> <target>${java.source.version}</target> </configuration> </plugin> </plugins> </pluginManagement> </build>
我总是收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:3.0.1:pmd (pmd) on project my_project: An error has occurred in PMD Report report generation. Could not find resource 'rulesets/java/unit.xml'
maven pmd 插件依赖于 pmd,所以捆绑的规则集应该是类路径的一部分,或者?Maven pmd 插件手册说捆绑的规则集应该用相对路径定义,而自定义规则集应该用绝对路径定义。但是,我认为它也可以通过相对路径读取我的自定义规则集,因为它是类路径的一部分。我还尝试了其他事情,例如,在 maven pmd 插件中显式附加依赖项定义 pmd。但是,到目前为止没有任何成功:\