- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个由 Maven 3.2.1 构建的 Java 7 项目。我在构建时使用 PMD 分析我的源代码(maven-pmd-plugin:3.2
,它在后台使用 net.sourceforge.pmd:pmd:5.1.2
)。
给定一个包含一个违规的简单类,我的 Maven 输出会将该违规打印两次,但我不希望出现重复的违规,因为它具有误导性且更难阅读。
public class Main {
public static void main(final String[] args) {
System.out.println("hello");
}
}
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>
<groupId>com.stackoverflow</groupId>
<artifactId>pmd-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.2</version>
<configuration>
<linkXref>false</linkXref>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.7</targetJdk>
<minimumPriority>2</minimumPriority>
<rulesets>
<ruleset>/rulesets/java/logging-java.xml</ruleset>
</rulesets>
<failurePriority>2</failurePriority>
<printFailingErrors>true</printFailingErrors>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
mvn prepare-package
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building pmd-test 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pmd-test ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ pmd-test ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Projects\pmd-test\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pmd-test ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pmd-test ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ pmd-test ---
[INFO]
[INFO] >>> maven-pmd-plugin:3.2:check (default) @ pmd-test >>>
[INFO]
[INFO] --- maven-pmd-plugin:3.2:pmd (pmd) @ pmd-test ---
[WARNING] Unable to locate Source XRef to link to - DISABLED
[INFO]
[INFO] <<< maven-pmd-plugin:3.2:check (default) @ pmd-test <<<
[INFO]
[INFO] --- maven-pmd-plugin:3.2:check (default) @ pmd-test ---
[INFO] PMD Failure: Main:4 Rule:SystemPrintln Priority:2 System.out.println is used.
[INFO] PMD Failure: Main:4 Rule:SystemPrintln Priority:2 System.out.println is used.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.161 s
[INFO] Finished at: 2016-07-06T20:21:41-08:00
[INFO] Final Memory: 21M/308M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:3.2:check (default) on project pmd-test: You have 1 PMD violation. For more details see:C:\Projects\pmd-test\target\pmd.xml -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
具体来说,它打印
[INFO] --- maven-pmd-plugin:3.2:check (default) @ pmd-test ---
[INFO] PMD Failure: Main:4 Rule:SystemPrintln Priority:2 System.out.println is used.
[INFO] PMD Failure: Main:4 Rule:SystemPrintln Priority:2 System.out.println is used.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
但我想打印
[INFO] --- maven-pmd-plugin:3.2:check (default) @ pmd-test ---
[INFO] PMD Failure: Main:4 Rule:SystemPrintln Priority:2 System.out.println is used.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
maven-pmd-plugin:3.6
,这是截至 2016 年 7 月 6 日的最新版本,它没有改变输出。最佳答案
这个问题是由于我对 Maven PMD 插件的错误配置造成的。
要解决此问题以便每次违规仅打印一次,请更改 maven-pmd-plugin
的配置以禁用 printFailingErrors
或 verbose
。它们都默认为 false
,因此删除其中一个元素即可解决问题。
pom.xml
中的固定插件配置示例<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.2</version>
<configuration>
<linkXref>false</linkXref>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.7</targetJdk>
<minimumPriority>2</minimumPriority>
<rulesets>
<ruleset>/rulesets/java/logging-java.xml</ruleset>
</rulesets>
<failurePriority>2</failurePriority>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
我认为详细模式应该只打印不会打印的错误或警告,以使其与曾经制作的所有其他日志记录系统保持一致,但我们做到了。
关于java - 防止PMD二次打印违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38237227/
我的 build.gradle 中有 PMD 检查,如下所示: apply plugin: "pmd" dependencies { pmd "net.sourceforge.pmd:pmd-ja
我正在阅读一个有趣的教程:http://www.avajava.com/tutorials/lessons/how-do-i-generate-pmd-and-cpd-reports-for-a-si
我想知道是否有办法从命令行运行所有 PMD 规则集。 我使用了与 Eclipse IDE 和 Maven 集成的 PMD。但现在我需要从 CLI 运行它。 我已经检查过这个页面 http://pmd.
我正在修改我的应用程序代码以遵守 pmd 规则。我在这段代码中有一个关闭资源错误: Connection c = DataSourceUtils.getConnection(dataSource);
是否有工具或插件来跟踪每个开发人员的 PMD、CheckStyle 和 Findbugs 不合规报告 谢谢韩国 最佳答案 似乎Sonar是你需要的 Sonar is an open source qu
我想在 PMD 中使用自定义规则。我在 jenkins 中安装了 PMD 插件,我还创建了一个 jar: 规则集文件 自定义规则的java代码(自定义规则扩展自AbstractJavaRule)。 我
http://maven.apache.org/plugins/maven-pmd-plugin/目前版本为 2.4,支持 PMD 版本 4.2.2 是否可以将 PMD 版本 4.2.5 与此插件一起
我们如何在 eclipse pmd 插件中添加新的基于 java 的 pmd 规则? 我收到以下错误: 无效的类实现。类必须在插件类路径中并实现规则接口(interface)。 我用 Abstract
我在 Jenkins 上使用 Sonar 的 PMD 插件对我的代码进行静态分析。我也在运行 Eclipse 的 PMD 插件(准确地说是 eclipse-pmd 1.5 ( http://marke
我想通过永久链接使用我的 Sonar PMD 配置, 这是我的 maven pom.xml 的构建部分 install org.apach
我们的 Jenkins 实例中有许多 Maven 作业,每个作业都有自己特定的调用字符串,在构建配置中指定,类似于 mvn clean install -DDISABLED="javadoc:aggr
PMD和SonarQube是一个很好的工具,但是我在抑制PMD警告时遇到了问题。 我们在项目中经常使用Lombok,因此许多模型类都有: @SuppressWarnings(“PMD.UnusedPr
也许只有我一个人,但是我找不到PMD中具有最高优先级的信息: 1 或 5 吗? 由于http://pmd.sourceforge.net/running.html和命令行参数-minimumprior
是否有很好的资源来描述 PMD 规则集背后的“原因”? PMD's site有“什么”——每条规则的作用——但它没有描述为什么 PMD 有这条规则,以及为什么忽略这条规则会给你在现实世界中带来麻烦。特
我用声纳开始了我的冒险;) 声纳的默认配置在主要级别设置了 PMD UnnecessaryLocalBeforeReturn 错误。 List filtered = em.createQuer
我正在尝试微调我们的 CI,但我无法弄清楚如何避免 PMD 在 src-gen 中报告生成代码的违规行为(不讨论那里的 Android R 文件): 我使用 mvn help:effective-po
我想在我的gradle项目中设置PMD,使其具有两个规则集,一个规则集是强制性的,可以中断构建,而另一个规则集只是报告但可以继续构建。这可能吗? 最佳答案 绝对有可能! 默认情况下,PMD插件将为每个
我在 Windows 上的 Eclipse 中使用 pmd 时出现严重的内存泄漏。我导入了一堆大型 Maven 项目。 m2e 和编译后 PMD 启动。然后,它最终在工作区中的许多(大约 50 个)项
如何定义 custom-rulesets.xml在父项目中,所以它在子模块中被重用? 我有一个运行良好的 PMD 示例项目 ( you can check later )。 但是,这个 Maven 项
我正在创建一个基于 maven 的 java 项目,其中包含 PMD maven 插件。我使用我自己的规则集 XML,它的工作原理就像一个魅力,除了两个规则集:emptycode 和 unnecess
我是一名优秀的程序员,十分优秀!