如何在Maven多模块项目中生成PMD报告?

时间:2023-01-13 12:50:06

I am new to configuration for all the code-analysis tool link PMD,CheckStyle,Sonar. I have multi-module maven project.I created separate sub-module for code-analysis.I want to run PMD on my all sub-module and to achieve as html report. project requirement is to keep separate code for code analysis.

我是所有代码分析工具链接PMD,CheckStyle,Sonar的新配置。我有多模块maven项目。我为代码分析创建了独立的子模块。我想在我的所有子模块上运行PMD并实现html报告。项目要求是为代码分析保留单独的代码。

Project Structure.

project-parent
 |
 |-sub-module1
 |   |-pom.xml(sub-module1 pom)
 |-sub-moduel2
 |   |-pom.xml (sub-moduel2 pom)
 |-code-analysis
 |   |-pom.xml (Using this pom i want to generate report for PMD)
 |
 |-pom.xml (parent pom)

I just started pom.xml ( under code-analysis )

我刚开始使用pom.xml(在代码分析下)

pom.xml

 <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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.spring.web</groupId>
    <artifactId>project-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>code-analysis</artifactId>
  <name>code-analysis</name>



  <properties>
      <maven.pmd.plugin.version>3.4</maven.pmd.plugin.version>
      <maven.jxr.version>2.3</maven.jxr.version>
      <maven.javadoc.plugin>2.8.1</maven.javadoc.plugin>

      <main.basedir>${project.parent.basedir}</main.basedir>

      <maven.checkstyle.plugin>2.7</maven.checkstyle.plugin>

      <maven.jxr.plugin>2.3</maven.jxr.plugin>
      <maven.pmd.plugin>2.7.1</maven.pmd.plugin>
      <maven.sonar.plugin>3.2-RC3</maven.sonar.plugin>
      <maven.surefire.plugin>2.12</maven.surefire.plugin>
      <maven.taglist.plugin>2.4</maven.taglist.plugin>

      <maven.versions.plugin>1.3.1</maven.versions.plugin>

      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>


  </properties>

     <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>${maven.jxr.version}</version>
            </plugin>
        </plugins>
    </reporting>


  <build>


  <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>${maven.pmd.plugin.version}</version>
      </plugin>


       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>${maven.javadoc.plugin}</version>
        <configuration><aggregate>true</aggregate>
        </configuration>
       </plugin>

   </plugins>

  </build>
 </project>

2 个解决方案

#1


Use the <format>html</format> setting of the plugin.

使用插件的 html 设置。

maven-pmd-plugin

#2


Use the <aggregate>true</aggregate> settings of the plugin.

使用插件的 true 设置。

More configurations, please see http://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html

更多配置,请参阅http://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html

#1


Use the <format>html</format> setting of the plugin.

使用插件的 html 设置。

maven-pmd-plugin

#2


Use the <aggregate>true</aggregate> settings of the plugin.

使用插件的 true 设置。

More configurations, please see http://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html

更多配置,请参阅http://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html