Maven PMD插件无法使用"mvn网站"命令或"pmd:pmd"生成报告 [英] Maven PMD plug-in not generating a report with 'mvn site' command or 'pmd:pmd'

查看:128
本文介绍了Maven PMD插件无法使用"mvn网站"命令或"pmd:pmd"生成报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读有趣的教程:

I am reading an interesting tutorial here: http://www.avajava.com/tutorials/lessons/how-do-i-generate-pmd-and-cpd-reports-for-a-site.html?page=1

本教程介绍了如何使用Maven运行开源静态分析工具PMD,以及如何在Maven创建的网站上查看生成的输出. Maven可以轻松地使用mvn site命令创建网站,但是本教程介绍了如何使用PMD来获得有关源代码的更有用的指标.

This tutorial shows how to use Maven to run the open-source static-analysis tool, PMD, and to see the generated output on a Maven created website. Maven can easily create websites with mvn site command, but this tutorial shows how to use PMD for more helpful metrics on the source code.

我已尽其所能按照说明进行操作.这是我的pom.xml文件,来自阅读本教程:

The instructions were followed to the best of my ability. Here is my pom.xml file that came from reading the tutorial:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.name.bookstore</groupId>
  <artifactId>bookstore</artifactId>
  <packaging>jar</packaging>
  <version>1</version>
  <name>bookstore</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <extensions>
      <!-- start for deploying using webdav -->
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-webdav</artifactId>
        <version>1.0-beta-2</version>
      </extension>
    </extensions>
  </build>

  <distributionManagement>
    <!-- start -location where site is deployed -->
    <site>
      <id>site.deployments</id>
      <name>Site deployments</name>
      <url>dav:localhost/${basedir}</url>
    </site>
  </distributionManagement>

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>3.4</version>

      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
        <version>2.5</version>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.10.1</version>
      </plugin>
    </plugins>
  </reporting>

</project>

当我运行命令:mvn clean site时,我得到了一个由Maven构建的网站,其中包含许多不同的页面,但是这些页面均未显示任何与PMD有关的信息.我在这里想念什么? 为什么在生成的网站上看不到关于PMD的任何信息?

When I run the command: mvn clean site I get a website built by Maven with a bunch of different pages but none of them show anything in regards to PMD. What am I missing here? Why am I not seeing anything in regards to PMD in the generated website?

此外,当我运行mvn pmd:pmd时,构建成功,但是没有获得任何有用的PMD指标.我什至在上面链接的教程中所示,在我的一个Java源文件中编码了一些未使用的变量和方法,但是没有任何有用的输出.

Also, when I run mvn pmd:pmd there is a successful build but I do not obtain any helpful PMD metrics. I even coded in some unused variables and methods in one of my Java source files as illustrated in the above linked tutorial and there is no helpful output.

虽然mvn pmd:pmd命令确实可以创建一些文件.几个是看起来像引擎的规则文件,而其他则是空的.请在下面查看此屏幕截图:

The mvn pmd:pmd command does appear to create some files though. A couple are files of rules for the engine it looks like and the others are empty. Please see the screen-shots of this below:

图1 :由pmd:pmd命令创建的文件

Figure 1: Files created by pmd:pmd command

图2 :空的pmd文件-即使Java源文件中存在明显的错误

Figure 2: Empty pmd file - even though there are obvious errors in Java source file

外面有人知道发生了什么吗?为什么PMD不为我使用Maven?

Does anyone out there know what is up? Why is PMD not working with Maven for me?

感谢您阅读本文.

此外,根据我在 PMD网站上浏览的内容, Maven的网站中, 项目报告"部分.虽然这里没有来自PMD的数据.请参见下面的屏幕截图.

Also, from what I have read around the Internet on PMD's website and Maven's website there should be some information in the "Project Reports" section. There is no data here though from PMD. Please see the below screen-shot.

图3 :在项目报告中找不到PMD数据

Figure 3: No PMD Data found in Project Reports

致谢

更新

当我将pom.xml文件的PMD部分更改为以下代码片段时,我通过PMD获得了一些CPD结果,但是对于代码错误,仍然没有获得PMD的帮助.我什至在NullPointerException中进行了编码,即使发出mvn pmd:check命令,PMD也什么也没说.

When I change the PMD section of the pom.xml file to the below snippet I obtain some CPD results via PMD but still nothing from PMD on code bugs. I even coded in an NullPointerException and PMD said nothing even when issuing the mvn pmd:check command.

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>3.4</version>
    <configuration>

      <linkXref>true</linkXref>
      <sourceEncoding>utf-8</sourceEncoding>
      <minimumTokens>1</minimumTokens>
      <targetJdk>1.7</targetJdk>
    </configuration>
  </plugin>

在代码段中,我将sourceEncoding标记更改为utf-8,因为与此相关的所有内容均为utf-8.我还将minimumTokens值更改为1,以尝试从该插件获得更多输出.我也将此片段放在<build>部分中以尝试获取结果,但仍然没有任何结果...:/

In the snippet I changed the sourceEncoding tag to be utf-8 because everything I see in regards to this is utf-8. I also changed the minimumTokens value to 1 to try to get more output from this plug-in. I also put this snippet in the <build> section to try and get results but still nothing... :/

感谢您对此进行研究...

Thanks for studying this...

推荐答案

skipEmptyReport ).您需要将其设置为false,以始终进入您的网站以获取PMD/CPD报告:

The maven-pmd-plugin by default skips nowadays empty reports (property skipEmptyReport). You'll need to set this to false, to get in your site always a PMD/CPD report:

<reporting>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-pmd-plugin</artifactId>
      <version>3.4</version>
      <configuration>
        <skipEmptyReport>false</skipEmptyReport>
      </configuration>
    </plugin>
  </plugins>
</reporting>

这适用于PMD和CPD.我假设这是您的问题,如图2所示,没有检测到PMD违规(pmd.xml文件为空).

This applies for both PMD and CPD. I assume, this is your problem, as in Figure 2, you show, there are no PMD violations detected (pmd.xml file is empty).

属性 minimumTokens 配置CPD并定义必须至少将代码片段重复多长时间才能声明为重复代码.数字越低,检测到的重复项越多,但是重复项也可能更短,因此可能更容易出现误报.

The property minimumTokens configures CPD and defines how long a code snipped at a minimum must be to be declared as a duplicate. The lower the number, the more duplicates are detected, but the duplicates can also be much shorter and therefore maybe more often false positives.

在没有进一步配置maven-pmd-plugin的情况下,它默认使用以下三个PMD规则集: java导入 规则 .如果要检测特定问题,则需要启用这些规则.另请参见如何制作规则集.

Without further configuring maven-pmd-plugin it uses by default these three PMD rulesets: java-basic, java-imports, java-unusedcode. See also property rulesets. If you want to detect specific problems, then you'll need to enable these rules. See also How to make a ruleset.

这篇关于Maven PMD插件无法使用"mvn网站"命令或"pmd:pmd"生成报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆