我有一个自定义规则集定义,它引用了捆绑规则集中的一堆规则。但是,我在maven pmd插件中解决这些捆绑规则集时遇到问题。 Here是一个相关的问题,有一个针对此问题的快速解决方案。但是,我想知道这个问题是否可能有一个干净的解决方案(因为我认为这是一个相当常见的用例,或者?)。 在下文中,我描述了我到目前为止所尝试的尝试:
<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 plugin manual表示应使用相对路径定义捆绑规则集,并使用绝对路径定义自定义规则集。但是,我认为它也可以通过相对路径读取我的自定义规则集,因为它是类路径的一部分。 我还尝试了其他的东西,例如,maven pmd插件中的pmd的显式附加依赖项定义。然而,到目前为止没有任何成功:\