java 如何在 Maven 安装期间抑制 PMD 警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13072280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to suppress PMD warnings during a Maven install
提问by ecbrodie
I have a Java project that is built using Maven, thus my build process is defined in the pom.xmlfile of the project. My development team uses a variety of plugins to check the quality of our source code; one such plugin uses PMDto check the code.The plugin makes sure that PMD is run every time we execute mvn install
on the project and it will fail the build if there is a violation. Here is the plugin in our pom.xml:
我有一个使用Maven构建的 Java 项目,因此我的构建过程在项目的pom.xml文件中定义。我的开发团队使用各种插件来检查我们源代码的质量;一个这样的插件使用PMD来检查代码。该插件确保每次我们mvn install
在项目上执行时都运行 PMD ,如果存在违规,它将导致构建失败。这是我们 pom.xml 中的插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<targetJdk>1.6</targetJdk>
<linkXref>false</linkXref>
<failOnViolation>true</failOnViolation>
<failurePriority>1</failurePriority>
<rulesets>
<ruleset>config/pmd-rulesets.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
My problem is that there are some times -- especially when I am in the middle of developing a task and I want to check out if my code builds, but before I am ready to submit my source code to the SCM for automatic build and release to others -- when I will want to suppress PMD violations from failing my build. I know that one such solution is to go into the code and add annotations to suppress warnings (http://pmd.sourceforge.net/suppressing.html), but I believe that editing source code in this way just to suppress these violations is annoying and error-prone. Another thing I could do is edit my pom and comment out the PMD plugin. However, once again, I find changing a file that is essential to my overall application is annoying and error-prone.
我的问题是有一些时候——尤其是当我正在开发一个任务并且我想检查我的代码是否构建时,但在我准备将我的源代码提交给 SCM 以进行自动构建和发布之前对其他人——当我想抑制 PMD 违规时我的构建失败。我知道一种这样的解决方案是进入代码并添加注释以抑制警告(http://pmd.sourceforge.net/suppressing.html),但我相信以这种方式编辑源代码只是为了抑制这些违规行为是烦人且容易出错。我可以做的另一件事是编辑我的 pom 并注释掉 PMD 插件。然而,我再次发现更改对我的整个应用程序至关重要的文件很烦人且容易出错。
The solution that my team desires for is one that allows us to simply pass in some sort of flag or argument into our mvn
command to quickly tell the build process to skip the PMD plugin. For example, whenever we are running an install at a point in the development phase and we know that the integration tests will probably fail (like, a web service may not be active), we pass the -Dskip.integration.tests=true
flag during mvn install
. This is a much cleaner solution than having to edit our test files or change pom.xml. I am looking for a similar variable to allows us to quickly skip PMD violations. Thanks!
我的团队想要的解决方案是允许我们简单地将某种标志或参数传递到我们的mvn
命令中,以快速告诉构建过程跳过 PMD 插件。例如,每当我们在开发阶段的某个时间点运行安装并且我们知道集成测试可能会失败(例如,Web 服务可能不活动)时,我们会-Dskip.integration.tests=true
在mvn install
. 这是一个比编辑我们的测试文件或更改 pom.xml 更简洁的解决方案。我正在寻找一个类似的变量来允许我们快速跳过 PMD 违规。谢谢!
PS: I did my homework. The following two Stackoverflow questions did not contain my desired solution:
PS:我做了功课。以下两个 Stackoverflow 问题没有包含我想要的解决方案:
回答by Eugene Kuleshov
Just declare failPmdOnViolation property in your pom.xml as true, specify that property in plugin settings instead of hardcoded constant and then you can override it by activating a special profile of from the command line. Or you can refer default expression for failOnViolation plugin propertylike mvn -Dpmd.failOnViolation=false install
只需将 pom.xml 中的 failPmdOnViolation 属性声明为 true,在插件设置中指定该属性而不是硬编码常量,然后您可以通过从命令行激活特殊配置文件来覆盖它。或者您可以参考failOnViolation 插件属性的默认表达式,例如mvn -Dpmd.failOnViolation=false install
回答by jAvA
I used below command the same way we use skipTests=true
.
我使用以下命令的方式与我们使用skipTests=true
.
mvn clean install -Dpmd.skip=true
Also for findbugs we can use
同样对于我们可以使用的 findbugs
-Dfindbugs.skip=true