我正在尝试在我的所有子模块中共享相同的 pmd 配置。我正在寻找实现这一目标的最佳方法
我认为我可以将它放在父项目中,就像我为 checkstyle 插件所做的那样
父 pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>/src/main/config/checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<rulesets>
<ruleset>pmd.xml</ruleset>
</rulesets>
<linkXref>true</linkXref>
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
<targetJdk>${maven.compiler.target}</targetJdk>
</configuration>
</plugin>
</plugins>
</build>
多模块结构
这是我的结构
parent
|-- src
| `-- main
| `-- resources
| |-- pmd.xml
| `-- checkstyle.xml
|-- pom.xml
|-- model
| `-- pom.xml
`-- webapp
`-- pom.xml
错误
使用此配置,我只会收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:2.7.1:pmd (default-cli) on project model: An error has occurred in PMD Report report generation. Could not find resource 'pmd.xml'. -> [Help 1]
解决方案 1
我尝试了这个对我有用的解决方案,因为我在子模块上只有一个级别:
但是在不久的将来,我可能会有更多的关卡,所以我不相信这是THE方法
${basedir}/../src/main/resources/pmd.xml
解决方案 2
在不编写所有解决方案的情况下,我可以使用程序集来压缩我的配置并在我的所有子模块中使用它作为依赖项。这适用于任何级别,但这太过分了!
这里有一个可以解释它的链接:How to include resources from war to another maven project
所以我正在寻找一个 Maven 技巧,但我不知道什么或如何!欢迎每个建议/线索。
最佳答案
有一个单独的模块,其中包含那些通用配置文件,如构建工具。然后,您可以将此模块作为依赖项添加到您的插件配置并加载它。
我已经在 ksoap2-android 项目的多个模块中使用 checkstyle 配置文件实现了一个示例。
https://github.com/mosabua/ksoap2-android/blob/master/pom.xml
关于maven - 在多模块 Maven 项目中共享特定的 PMD 规则集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14885048/