在多模块Maven项目中共享特定的PMD规则集 [英] Share specific PMD rulesets across multi module maven project
问题描述
我正在尝试在所有子模块上共享相同的pmd配置.我正在寻找实现这一目标的最佳方法
I'm trying to share the same pmd configuration across all my submodules. I'm looking for the best way to achieve that
我认为我可以将其放置在父项目中,就像我为checkstyle插件所做的那样
I thought that I could place it in the parent project, like I did it for checkstyle plugin
<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>
多模块结构
这是我的结构
Multi Module Structure
Here my structure
parent
|-- src
| `-- main
| `-- resources
| |-- pmd.xml
| `-- checkstyle.xml
|-- pom.xml
|-- model
| `-- pom.xml
`-- webapp
`-- pom.xml
错误
使用这种配置,我只会得到以下错误:
Error
With this configuration, I only obtain the following error :
[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
我尝试了适用于我的解决方案,因为子模块只有一个级别: 但是在不久的将来,我可能会有更多的水平,所以我不相信那是方法 $ {basedir}/../src/main/resources/pmd.xml
Solution 1
I tried this solution that works for me, because I only have one level on submodules : But in a close future, I may have more levels, so I'm not convinced that's THE method ${basedir}/../src/main/resources/pmd.xml
无需编写所有解决方案,我就可以使用程序集压缩我的配置,并将其作为依赖项在我的所有子模块中使用.这适用于任何级别,但是这太过分了!
Without writing all the solution, I can use an assembly to zip my config and use it in all my submodule as an dependency. This would work for any levels, but this is overkilling !
Here a link that would explain it: How to include resources from war to another maven project
所以我正在寻找Maven的把戏,但是我什么也没有!任何建议/提示都值得欢迎.
So I'm looking for a Maven trick, but I don't what or how ! Every advice / clue is welcome.
推荐答案
有一个单独的模块,其中包含诸如构建工具之类的通用配置文件.然后,您可以将此模块作为依赖项添加到插件配置并加载它.
Have a separate module that contains those generic config files like build-tools. Then you can add this module as a dependency to your plugin config and load it.
我已经在ksoap2-android项目中的多个模块上使用checkstyle配置文件实现了一个示例.
I have implemented an example of this with a checkstyle config file across a multiple modules in the ksoap2-android project.
https://github.com/mosabua/ksoap2-android/blob/master/pom.xml
这篇关于在多模块Maven项目中共享特定的PMD规则集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!