标签: pmd

PMD xpath规则警告在BigDecimal上使用equals()

有人建议PMD xpath规则警告调用equals()方法java.math.BigDecimal将检查值和规模通常(除非对于某些工程类型的应用程序)可能是一个错误.由于1.0不等于1.00,人们应该使用compareTo.

pmd

5
推荐指数
1
解决办法
454
查看次数

如何锁定maven插件版本

如何锁定我想要使用的Maven插件的版本?

我有PMD插件配置如下:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <outputDirectory>target/pmd</outputDirectory>
                    <targetDirectory>target/</targetDirectory>
                    <aggregate>true</aggregate>
                    <targetJdk>1.6</targetJdk>
                    <rulesets>
                        <ruleset>rulesets/basic.xml</ruleset>
                        <ruleset>rulesets/codesize.xml</ruleset>
                        <ruleset>rulesets/coupling.xml</ruleset>
                        <ruleset>rulesets/design.xml</ruleset>
                        <ruleset>rulesets/imports.xml</ruleset>
                        <ruleset>rulesets/logging-java.xml</ruleset>
                        <ruleset>rulesets/optimizations.xml</ruleset>
                        <ruleset>rulesets/strings.xml</ruleset>
                        <ruleset>rulesets/unusedcode.xml</ruleset>
                    </rulesets>
                </configuration>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

昨晚,我的夜间构建失败,我不能再运行任何pmd目标,因为它试图找到该插件的2.6-SNAPSHOT版本.如果我有一个2.5的版本标签,它为什么甚至试图找到2.6-SNAPSHOT?此外,2.6-SNAPSHOT不在中心 - 为什么我的maven客户认为它存在?

Maven版本:2.0.9
Java版本:1.6.0_17
操作系统名称:"linux"版本:"2.6.24-24-generic"arch:"i386"系列:"unix"

编辑:

我升级到maven 2.2.1并观察到与以前相同的问题.通过从我的存储库(.m2/repository/org/apache/maven/plugins/maven-pmd-plugin/maven-metadata-central.xml)中的元数据中删除2.6-SNAPSHOT,我能够构建项目.我还将latestVersion标记设置为2.5.这显然不是解决方案,因为我必须部署自己的插件或更改所有客户端上的缓存版本.

maven-2 pmd

5
推荐指数
1
解决办法
780
查看次数

Joshua Bloch的Builder模式和PMD警告

我使用Joshua Bloch的Builder模式编写了一个类,类似于这个Pizza示例:

public class Pizza {
  private int size;
  private boolean cheese;
  private boolean pepperoni;
  private boolean bacon;

  public static class Builder {
    //required
    private final int size;

    //optional
    private boolean cheese = false;
    private boolean pepperoni = false;
    private boolean bacon = false;

    public Builder(int size) {
      this.size = size;
    }

    public Builder cheese(boolean value) {
      cheese = value;
      return this;
    }

    public Builder pepperoni(boolean value) {
      pepperoni = value;
      return this;
    }

    public Builder bacon(boolean value) {
      bacon …
Run Code Online (Sandbox Code Playgroud)

java pmd builder-pattern

5
推荐指数
1
解决办法
5475
查看次数

PMD + Maven + JAVA错误::找不到资源rulesets / comments.xml。确保资源是有效文件或URL或在CLASSPATH上

在添加PMD的自定义规则集时,maven产生错误- net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource rulesets/comments.xml.Make sure the resource is a valid file or URL or is on the CLASSPATH

对于其他规则集,例如基本规则,命名规则等,它没有给出任何错误。但是当我添加新规则集时,它会产生错误。我也尝试过,<rule ref="rulesets/java/comments.xml/CommentRequired"/>但它也给出了同样的错误。在pmd-5.0.2.jar文件中已经可以使用comments.xml。

我的POM.xml

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

    <dependency>
        <groupId>pmd</groupId>
        <artifactId>pmd</artifactId>
        <version>5.0.2</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9.1</version>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/site/
                        </outputDirectory>
                        <reportOutputDirectory>${project.reporting.outputDirectory}/site/
                        </reportOutputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>2.7.1</version>
            <configuration>
                <targetjdk>1.6</targetjdk>
                <skip>fasle</skip>
                <failOnViolation>false</failOnViolation>
                <failurePriority>4</failurePriority>
                <verbose>true</verbose>
                <rulesets>
                    <ruleset>src/main/resources/rulesets/MyRuleSet.xml</ruleset>
                </rulesets>
            </configuration>
            <executions>
                <execution>
                    <id>check</id>
                    <goals>
                        <goal>check</goal>
                    </goals> …
Run Code Online (Sandbox Code Playgroud)

java pmd maven

5
推荐指数
1
解决办法
5176
查看次数

Gradle PMD Checkstyle Findbugs - 用于Java构建的sourceSet目录

Gradle 1.6 Linux.

Java构建项目结构

  • Project_or_Module
    • src/java(包含java源代码)
    • test/java(包含JUnit测试 - 单元测试)
    • src/java-test(包含集成测试)
    • etc/etc(项目下的其他.. ..文件夹)

我有以下全局配置/ build.gradle文件:

   apply plugin: 'java'
   apply plugin: 'pmd'
   apply plugin: 'findbugs'
   apply plugin: 'checkstyle'
   apply plugin: 'code-quality'
   apply plugin: 'jacoco'

   tasks.withType(Compile) {
     options.debug = true
     options.compilerArgs = ["-g"]
   }

   checkstyle {
        configFile = new File(rootDir, "config/checkstyle.xml")
        ignoreFailures = true
   }


   findbugs {
        ignoreFailures = true
   }

   pmd {
        ruleSets = ["basic", "braces", "design"]
        ignoreFailures = true
   }

   jacoco {
      toolVersion = "0.6.2.201302030002"
      reportsDir = file("$buildDir/customJacocoReportDir")
   }

   sourceSets { …
Run Code Online (Sandbox Code Playgroud)

findbugs ignore checkstyle pmd gradle

5
推荐指数
1
解决办法
8488
查看次数

如何在logger语句中检测字符串连接?

有没有办法配置Checkstyle,PMD或FindBugs Maven插件来检测这样的代码:

logger.debug("string" + stringVariable);
Run Code Online (Sandbox Code Playgroud)

代替:

logger.debug("format string {}", stringVariable);
Run Code Online (Sandbox Code Playgroud)

java findbugs checkstyle pmd maven

5
推荐指数
2
解决办法
1504
查看次数

是否有任何Checkstyle/PMD/Findbugs规则强制"else if"在同一条线上?

在我们的链接if/else /项目中,如果我们想要进行以下格式化:

if (flag1) {
    // Do something 1
} else if (flag2) {
    // Do something 2
} else if (flag3) {
    // Do something 3
}
Run Code Online (Sandbox Code Playgroud)

并禁止以下一个:

if (flag1) {
    // Do something 1
} else {
    if (flag2) {
        // Do something 2
    } else {
        if (flag3) {
            // Do something 3
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

上面列出的静态代码分析工具中是否有一些预定义规则强制使用此代码样式?如果不是 - 我知道有能力在所有这些工具中编写自定义规则,您建议实施这样的规则(不熟悉在其中任何一个中编写自定义规则)?

java findbugs checkstyle pmd

5
推荐指数
1
解决办法
550
查看次数

PMD/checkstyle/findbugs的自定义规则集的建议位置是什么?

将Maven与PMD,Checkstyle和/或Findbugs的各种插件一起使用时,放置自定义规则集文件的推荐位置是什么?

findbugs checkstyle pmd maven

5
推荐指数
1
解决办法
102
查看次数

如何获得Gradle使用PMD 6.x类别?

我正在使用Gradle 4.5.1和标准的Gradle插件。我特别要求我的构建使用PMD 6.1.0,如下所示:

apply plugin: "pmd"

pmd {
    toolVersion = "6.1.0"
}

pmdMain {
    rulSets = ["java-basic"]
}
Run Code Online (Sandbox Code Playgroud)

一切都通过了,但是在控制台中,我收到了许多弃用警告,其内容如下:

使用“规则名称” category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop代替不推荐使用的“规则名称” rulesets/java/basic.xml/AvoidBranchingStatementAsLastInLoop。PMD 7.0.0将删除对此不建议使用的规则名称的支持。

我最初的想法是pmdMain像这样更改块:

pmdMain {
    rulSets = ["java-errorprone"]
}
Run Code Online (Sandbox Code Playgroud)

但是,我收到此错误:

找不到规则“ java-errorprone”的资源“ null”。确保资源是有效文件或URL,并且在CLASSPATH上。这是当前的类路径:~\.gradle\wrapper\dists\gradle-4.5.1-bin\a5vbgfvpwtoqz8v2cdivxz28k\gradle-4.5.1\lib\gradle-launcher-4.5.1.jar

我做错了什么吗?Gradle的PMD插件与PMD 6.x不兼容吗?

pmd gradle

5
推荐指数
1
解决办法
975
查看次数

与maven父模块中的Checkstyle和PMD配置不同

我有一个maven的java应用程序具有以下结构:

parent
| - pom.xml
| - child
    | - pom.xml
| - analyzers
    | - pmdrules.xml
    | - checkstyle.xml
Run Code Online (Sandbox Code Playgroud)

我在父pom.xml中配置了PMD和checkstyle.对于PMD,规则集配置如下,它对父模块和子模块都可以正常工作:

<configuration>
    <rulesets>
        <ruleset>${basedir}/../analyzers/pmdrules.xml</ruleset>
    </rulesets>
</configuration>
Run Code Online (Sandbox Code Playgroud)

但是,对于checkstyle,如果我以相同的方式配置configLocation,它在父节点或子节点中都会失败.我必须使用自定义属性来克服这个问题.

<configuration>
    <!-- Below config with ${projectRootDir}, a custom property always pointing to parent root works fine -->
    <configLocation>${projectRootDir}/analyzers/checkstyle.xml</configLocation>
    <!-- Below configurations with ${basedir} will fail build for child -->
    <!--<configLocation>${basedir}/analyzers/checkstyle.xml</configLocation>-->
    <!-- Below configurations with ${basedir} will fail build for parent -->
    <!--<configLocation>${basedir}/../analyzers/checkstyle.xml</configLocation>-->
</configuration>
Run Code Online (Sandbox Code Playgroud)

这是一个复制器样本 - https://github.com/ramtech123/pocs/blob/master/myapp-parent-module/pom.xml

我尝试在调试模式下运行maven构建.从日志中,对我而言,实际的PMD执行似乎仅针对子模块进行,因此它没有问题.

有人可以帮我理解根本原因,并改善我的配置.

提前致谢.

java checkstyle pmd maven maven-checkstyle-plugin

5
推荐指数
1
解决办法
310
查看次数