Share specific PMD rulesets across multi module maven project

坚强是说给别人听的谎言 提交于 2019-12-01 04:42:38

问题


I'm trying to share the same pmd configuration across all my submodules. I'm looking for the best way to achieve that

I thought that I could place it in the parent project, like I did it for checkstyle plugin

Parent 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>

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]

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

Solution 2

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

So I'm looking for a Maven trick, but I don't what or how ! Every advice / clue is welcome.


回答1:


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.

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




回答2:


I was reading the documentation for the ruleset tag and it says

The rule sets may reside in the classpath, filesystem or at a URL. For rule sets that are bundled with the PMD tool, you do not need to specificy the absolute path of the file. It will be resolved by the plugin. But if the rule set is a custom rule set, you need to specify its absolute path.

I solved the problem of sharing my PMD settings across my multi-maven build by specifying the URL to the ruleset file in my parent pom. (My repo was http accessible). Unfortunately this won't work though if you don't have your repo http accessible, but many people may.



来源:https://stackoverflow.com/questions/14885048/share-specific-pmd-rulesets-across-multi-module-maven-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!