maven-pmd-plugin 仅使用捆绑的规则集

发布于 2024-12-19 12:54:46 字数 1530 浏览 3 评论 0原文

我在我的项目中使用 maven-pmd-plugin,这就是我的配置方式

<reporting>
 <plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jxr-plugin</artifactId>
    <version>2.3</version>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>2.6</version>
    <configuration>
     <linkXref>true</linkXref>
     <sourceEncoding>UTF-8</sourceEncoding>
     <minimumTokens>100</minimumTokens>
     <targetJdk>${targetJdk}</targetJdk>
       <rulesets>
           <ruleset>${maven.pmd.rulesetfiles}</ruleset>
       </rulesets>
    </configuration>
  </plugin>
 </plugins>
</reporting>

以下是上述配置中使用的属性

<properties>
<spring.version>3.0.6.RELEASE</spring.version>
<basedir>C:\Users\Q4\workspace\project</basedir>
<maven.pmd.rulesetfiles>${basedir}\pmdRuleset.xml</maven.pmd.rulesetfiles>
<targetJdk>1.5</targetJdk>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

问题是当我运行 mvn pmd:check 时,它给了我 8 次违规 - 仅来自基本的、未使用的代码和导入。它根本不使用我在自定义规则集文件中列出的所有规则。我什至尝试直接在规则集中使用logging-java.xml和strings.xml,而不使用自定义规则集文件,但它仍然不起作用。

当我运行 mvn pmd:pmd 时,我获得了构建成功,但错误仍然出现在我的目标文件夹中。为什么我在这里构建成功?

I am using the maven-pmd-plugin on my project and this is how I have configured it

<reporting>
 <plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jxr-plugin</artifactId>
    <version>2.3</version>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>2.6</version>
    <configuration>
     <linkXref>true</linkXref>
     <sourceEncoding>UTF-8</sourceEncoding>
     <minimumTokens>100</minimumTokens>
     <targetJdk>${targetJdk}</targetJdk>
       <rulesets>
           <ruleset>${maven.pmd.rulesetfiles}</ruleset>
       </rulesets>
    </configuration>
  </plugin>
 </plugins>
</reporting>

Here are the properties used in the above configuration

<properties>
<spring.version>3.0.6.RELEASE</spring.version>
<basedir>C:\Users\Q4\workspace\project</basedir>
<maven.pmd.rulesetfiles>${basedir}\pmdRuleset.xml</maven.pmd.rulesetfiles>
<targetJdk>1.5</targetJdk>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

The problem is when I run mvn pmd:check, it gives me 8 violations -- only from the basic, unusedcode and imports. It simply doesn't use all the rules that I have listed in the custom ruleset file. I have even tried using the logging-java.xml and strings.xml directly in the ruleset without using the custom ruleset file and it still doesn't work.

When i run mvn pmd:pmd, i get a BUILD SUCCESS but the errors still show up in my target folder. Why do I get a build success here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

油饼 2024-12-26 12:54:46

我通过简单地将插件添加到构建部分以及报告部分中来解决这个问题。

不知何故,它也需要能够运行所有规则集。早些时候,我的印象是,只有当我们想在构建和部署阶段运行插件时,我们才会将插件放入构建中。

I solved this by simply adding the plugins in the build section along with the ones in the reporting section.

Somehow it needed to be in the as well to be able to run all the rulesets. Earlier I was under the impression that we put plugins in the build only if we want to run them during the build and deploy phase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文