Separate specific PMD rules for multiple maven modules

I am trying to use the same pmd configuration for all my submodules. I am looking for the best way to achieve this.

I thought I could place it in the parent project, for example, I did it for the 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> 

The structure of several modules

Here is my structure

 parent |-- src | `-- main | `-- resources | |-- pmd.xml | `-- checkstyle.xml |-- pom.xml |-- model | `-- pom.xml `-- webapp `-- pom.xml 

Error

With this configuration, I get only 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, which works for me because I have only one level on the submodules: But in the near future I may have more levels, so I'm not sure if the method $ {Base_Folder_name} /../ SRC / main / resources / pmd.xml

Decision 2

Without writing the whole solution, I can use the assembly for the zip configuration and use it in all my submodules as a dependency. It will work at any level, but it is too difficult!

Here is a link that explains this: How to incorporate resources from war into another maven project

So I'm looking for a Maven trick, but I don't know what and how! Every tip / tip is appreciated.

+4
source share
2 answers

You have a separate module containing these common configuration files, such as collectors. Then you can add this module as a function of your plugin configuration and download it.

I implemented an example of this with the checkstyle configuration file through several modules in the ksoap2-android project.

https://github.com/mosabua/ksoap2-android/blob/master/pom.xml

+3
source

I read the documentation for the ruleset tag and it says

Rule sets can be in the classpath, file system, or URL. For rule sets that are associated with the PMD tool, you do not need a specific absolute file path. He will be allowed 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 in my multi-maven assembly by specifying the URL of the rule set file in my parent folder. (My repo was available http). Unfortunately, this will not work if you do not have your http repo, but many can.

+1
source

All Articles