1 回答

TA貢獻1836條經驗 獲得超13個贊
這似乎是 PMD 中的一個錯誤,因為它在通過推斷的“var”跟蹤變量類型時存在問題。目標方法具有明確定義的參數。
我可以通過禁用特定的 PMD 規則來解決這個問題。在 pom.xml 中,我修改 PMD 插件以使用本地規則文件。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.12.0</version>
<configuration>
<linkXRef>false</linkXRef>
<printFailingErrors>true</printFailingErrors>
<failOnViolation>true</failOnViolation>
<rulesets>
<ruleset>${basedir}/PMD.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
以及 PMD.xml 文件(位于項目的根目錄中)。
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Default Maven PMD Plugin Ruleset" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
Excluding rules.
</description>
<rule ref="category/java/bestpractices.xml">
<exclude name="UnusedPrivateMethod"/>
</rule>
</ruleset>
添加回答
舉報