------ Multimodule Configuration ------ ------ 2016-09-25 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Multimodule Configuration If you have a multimodule project with many modules and you want to share the PMD ruleset configuration, so that each module uses the same PMD rules, this is possible, but requires a little setup. The setup is very similar to the one described for Checkstyle, see {{{https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html}Multimodule Configuration for Checkstyle}}. This example will use the same mysterious project called . This is what the structure of that project looks like: +-----+ whizbang |-- pom.xml |-- core | `-- pom.xml |-- gui | `-- pom.xml |-- jmx | `-- pom.xml `-- src +-----+ * Create a subproject for the PMD rulesets We'll start by adding another sub project that will house our common configuration for PMD. Let's call it . In it we put the resources that we want to share between our whizbang modules. In this example, we will add our custom PMD ruleset to be used by the PMD Plugin. The same subproject can be used to house shared configurations for Checkstyle. +-----+ whizbang |-- pom.xml |-- build-tools | |-- src | | `-- main | | `-- resources | | `-- whizbang | | `-- pmd-ruleset.xml | `-- pom.xml |-- core |-- gui |-- jmx `-- src +-----+ <> put the resources into a subdirectory that you can ensure will be unique and not conflict with anyone else. The <<>> file for should look like this: +-----+ 4.0.0 com.example.whizbang build-tools 1.0 Build Tools +-----+ A sample <<>> could look lke this: +-----+ This ruleset defines the PMD rules for project "whizbang". +-----+ The ruleset references the default rulesets. For more information about rulesets, see {{{http://pmd.github.io/pmd-5.5.1/customizing/howtomakearuleset.html}How to make a new ruleset}}. * Configure the other projects to use it Now we can include the PMD configuration in the top level <<>>. <> You have to specify a plugin dependency on <<>> in the <<<\>>> element of your <<>>. It will not work inside the <<<\>>> element, because <<<\>>> does not support plugin dependencies. The rest of the configuration is done in the normal way in the <<<\>>> element. +-----+ 4.0.0 com.example.whizbang whizbang-parent 1.0 pom WhizBang Parent org.apache.maven.plugins maven-pmd-plugin ${project.version} whizbang/pmd-ruleset.xml true check com.example.whizbang build-tools 1.0 org.apache.maven.plugins maven-pmd-plugin ${project.version} whizbang/pmd-ruleset.xml build-tools core jmx gui +-----+ Once you are done with that, ensure that you do not include the Maven PMD Plugin in your sub modules, as their definition and configuration, will override the top level parent pom's definition. Based on the PMD Plugin configuration above, the values of <<>> will be resolved from the classpath. The JAR was included in the classpath when it was declared as a dependency to the plugin. Lastly, kick off a build of the site. +-----+ mvn site +-----+ Or run the check goal of the PMD plugin via verify: +-----+ mvn verify +-----+ Every sub project will now use the same PMD setup and configuration.