java - PMD 规则集未通过 MAVEN 下载/更新

标签 java maven pmd

我尝试将 PMD 集成到我的一个项目中(我正在使用 MAVEN 构建工具) 当我尝试集成时,我可以看到 XML 配置文件是必需的。 我尝试下载 PMD 插件 - 我预计全局规则集文件可能在 PMD 插件中可用,但事实并非如此。 我使用了下面的链接: https://sourceforge.net/projects/pmd/?source=typ_redirect

谷歌搜索后,我看到了一个获取规则集的链接 http://grepcode.com/file/repo1.maven.org/maven2/pmd/pmd/4.3 我无法下载所有 XML 文件。

有没有办法通过构建下载/更新,或者我们可以在任何地方的一个位置获取所有 XML 文件吗?我尽了最大努力在谷歌中搜索,但无法找到答案。

我在这里附加了pom.xml。您能否告诉我如何在 PMD 自动更新时自动添加我的规则集?

<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>
  <groupId>com.scm</groupId>
  <artifactId>parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>SCM-PRODUCT</name>
  <description>SCM Product for learning purpose</description>
  <properties>
    <java.version>1.7</java.version>
    <hibernate.validator.version>5.2.4.Final</hibernate.validator.version>
    <javax.el-api.version>2.2.4</javax.el-api.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <checkstyle-config-url>
      D:/rules/checkstyle/2.0/checkstyle-2.0.xml
   </checkstyle-config-url>
    <checkstyle.version>6.18</checkstyle.version>

    <log4j.version>1.2.17</log4j.version>
    <!-- TEST CASES RELATED BEGINS-->

    <junit.version>4.12</junit.version>     

    <!-- TEST CASES RELATED ENDS HERE-->

    <!-- STATIC CODE ANALYSIS PROPERTIES -->
    <findbugs.plugin.version>3.0.3</findbugs.plugin.version> <!-- Reports on common code mistakes and pitfalls -->
    <checkstyle.plugin.version>5.0</checkstyle.plugin.version> <!-- Checks Code Style for Developers -->
    <pmd.plugin.version>3.6</pmd.plugin.version> <!-- Source Code Analyzer -->

    <doxia.module.markdown.version>1.3</doxia.module.markdown.version>
    <javadoc.plugin>2.8.1</javadoc.plugin> <!-- Generates JavaDoc -->
    <jxr.plugin>2.3</jxr.plugin> <!-- Cross reference report of project source code -->

    <!-- REPORTING TOOL PROPERTIES -->
    <project.info.reports.plugin>2.4</project.info.reports.plugin> <!-- A plethora of miscellaneous report: info, ci, dependencies, scm, plugins, etc. -->
    <site.plugin>3.1</site.plugin>
    <sonar.plugin>3.2-RC3</sonar.plugin> <!-- Analysis and metrics on code over time -->
    <surefire.plugin>2.12</surefire.plugin> <!-- Reports Test Results -->
    <taglist.plugin>2.4</taglist.plugin> <!-- Reports on Tags such as @todo and //TODO -->
    <versions.plugin>1.3.1</versions.plugin>
    <maven-compiler-plugin>3.1</maven-compiler-plugin>
    <cobertura.plugin>2.5.1</cobertura.plugin> <!-- Reports Test Coverage -->

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>
  <modules>
    <module>services</module>
    <module>presentation</module>
    <module>service_validator</module>
    <module>jsonvo</module>
  </modules>
  <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.validator.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>${javax.el-api.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- http://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/net.sourceforge.pmd/pmd -->
        <dependency>
            <groupId>net.sourceforge.pmd</groupId>
            <artifactId>pmd</artifactId>
            <version>5.4.2</version>
        </dependency>
    </dependencies>
  </dependencyManagement>
  <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugin</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <includeTests>true</includeTests>
                    <rulesets>
                        <ruleset>${checkstyle-config-url}</ruleset>
                    </rulesets>
                    <minimumTokens>100</minimumTokens>
                    <targetJdk>${java.version}</targetJdk>
                    <failOnViolation>true</failOnViolation>
                </configuration>
                <executions>
                    <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
                </executions>      
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>${pmd.plugin.version}</version>
                <configuration>
                    <targetJdk>${java.version}</targetJdk>
                    <minimumTokens>20</minimumTokens>
                    <skipEmptyReport>false</skipEmptyReport>
                    <failOnViolation>true</failOnViolation>
                    <printFailingErrors>true</printFailingErrors>
                    <!--<includeTests>true</includeTests>-->
                    <rulesets>
                        <ruleset>${pom.basedir}/pmd-rulesets.xml</ruleset>
                    </rulesets>
                    <!-- 
                    <excludeRoots>
                        <excludeRoot>target/generated-sources/antlr</excludeRoot>
                        <excludeRoot>target/generated-sources/antlr/com/puppycrawl/tools/checkstyle/grammars/javadoc</excludeRoot>
                    </excludeRoots>
                     -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>pmd</goal>
                            <goal>cpd</goal>
                            <goal>cpd-check</goal>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>${findbugs.plugin.version}</version>
                <configuration>
                    <effort>Max</effort>
                    <threshold>Low</threshold>
                    <excludeFilterFile>config/findbugs-exclude.xml</excludeFilterFile>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>

    </plugins>
  </build>
</project> 

最佳答案

如果您不需要使用自定义 pmd 规则集,则可以完全省略 rulesets 标记。

如果您只想使用某些 pmd 规则集,您可以使用预定义的规则集:

      <rulesets>
        <ruleset>/rulesets/java/braces.xml</ruleset>
        <ruleset>/rulesets/java/naming.xml</ruleset>
      </rulesets>

关于java - PMD 规则集未通过 MAVEN 下载/更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37894441/

相关文章:

netbeans - 如何从 Sonar 导出 FindBugs/PMD/Checkstyle 规则并导入到 Netbeans

java - 是否有任何 Checkstyle/PMD/Findbugs 规则强制 "else if"在同一行?

java - RMI 服务器连接拒绝主机 : ############ ; nested exception is: java.net.ConnectException:连接被拒绝:连接

java - 缺少对本地安装 Artifact 的 Maven 依赖

maven - 如何在生成的 pom(generatePom ...)中将 gradle 'compileOnly' 映射到 'provided'

eclipse - 是否有在 Maven 构建生命周期期间运行的测试的日志文件?

java - PMD 规则集文件

java - 使用 Multi-Tenancy 实现在单个事务期间切换数据源

java - Java API 中的构建器模式示例?

java - java计算的意外结果