- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 Gradle 中,我们可以为 pmdMain 和 pmdTest 源集指定不同的 PMD 配置(包括不同的规则集)。例如
pmdMain {
ruleSetFiles = files("$javaBuildSystemRoot/src-pmd-rulesets.xml")
}
pmdTest {
ruleSetFiles = files("$javaBuildSystemRoot/test-pmd-rulesets.xml")
}
我们希望测试代码不像主代码那么严格。
有一个单独的基于 Maven 的项目,目前我们无法使用 gradle。但目前,我们希望至少应用基于 main 和 test 的 2 个不同的规则集。它是一个单模块单项目,使用maven PMD插件。
我们如何在 Maven pom 文件中执行此操作?
最佳答案
pmd 测试源是“相当不传统的”,但这不是问题的一部分。 :)
使用executions标记和利用maven-pmd-plugin ,你可以使用maven来做到这一点。
<小时/>EDIT: In short & applied to the given input (and maybe more than you wanted/need), it enables/forces you to make both checks in every build:
<project><build><plugins>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.11.0</version> <!-- latest up-to-date -->
<executions>
<execution>
<id>pmd-execution</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rulesets>
<ruleset>/path/to/.../src-pmd-rulesets.xml</ruleset>
</rulesets>
</configuration>
</execution>
<execution>
<id>pmd-test-execution</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<includeTests>true</includeTests> <!-- this defaults to false! -->
<rulesets>
<ruleset>/path/to/.../test-pmd-rulesets.xml</ruleset>
</rulesets>
</configuration>
</execution>
</executions>
</plugin>
...
<小时/>
EDIT 2: If you indeed don't need "both executions" (in 1 build), but only "two configurations" for "different builds", then:Maven Profiles fits your needs (with profiles ... your "possibilities converge to infinity") !
您可以介绍如下个人资料:
<project>
...
<profiles>
<profile>
<id>pmdMain</id>
<properties>
<myPmdRuleSetLocation>/path/to/.../src-pmd-rulesets.xml</myPmdRuleSetLocation>
<myPmdTestsInclude>false</myPmdTestsInclude>
</properties>
</profile>
<profile>
<id>pmdTest</id>
<properties>
<myPmdRuleSetLocation>/path/to/.../test-pmd-rulesets.xml</myPmdRuleSetLocation>
<myPmdTestsInclude>true</myPmdTestsInclude>
</properties>
</profile>
<profiles>
...
</project>
并在您的(单次执行)pmd-plugin 配置中使用它:
...
<ruleset>${myPmdRuleSetLocation}</ruleset>
<includeTests>${myPmdTestsInclude}</includeTests>
...
请read further关于配置文件及其激活。
(另外 <profile/>
可以包含并覆盖 <build/>
标签!)
关于java - 我们如何在 Maven 中为主要和测试 java 代码集拥有不同的 PMD 规则集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54613445/
我的 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
我是一名优秀的程序员,十分优秀!