Bukama commented on issue #274:
URL: 
https://github.com/apache/maven-pmd-plugin/issues/274#issuecomment-7340174575

   As Andreas noted earlier, this isn't a plugin bug: it's how Maven applies 
plugin configuration. Some more details below.
   
   ### `mvn site`
   Your configuration **is** used here. All configured rulesets end up in 
`target/pmd/rulesets/`.
   
   ### `mvn pmd:pmd`
   When you invoke a report goal directly from the command line, Maven ignores 
the configuration in `<reporting>`. The [current Maven 
guide](https://maven.apache.org/guides/mini/guide-configuring-plugins.html#using-the-reporting-tag-vs-build-tag)
 says:
   
   > `mvn aplugin:areportgoal`
   > It **ignores** the parameters defined in the `<configuration>` element of 
each reporting Plugin specified in the `<reporting>` element; only parameters 
defined in the `<configuration>` element of each plugin specified in `<build>` 
are used.
   
   The passage you quoted comes from an older version of that guide. Maven core 
decides how configuration is injected into mojos, so the plugin can't change 
this.
   
   ### Rulesets in `<build>`
   `rulesets` is supported in the build configuration too. I checked with 
maven-pmd-plugin 3.28.0: with the configuration under `<build><plugins>`, `mvn 
pmd:pmd` extracts and applies the configured rulesets (`001-bestpractices.xml`, 
`002-codestyle.xml`, ...). With the configuration only under `<reporting>`, it 
uses `maven-pmd-plugin-default.xml`.
   
   ### Recommended setup
   To use the same configuration for `mvn site` and `mvn pmd:pmd`, put it in 
`<pluginManagement>` and reference the plugin from both sections:
   
   ```xml
   <build>
     <pluginManagement>
       <plugins>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-pmd-plugin</artifactId>
           <version>3.28.0</version>
           <configuration>
             <rulesets>
               <ruleset>/category/java/bestpractices.xml</ruleset>
               <ruleset>/category/java/errorprone.xml</ruleset>
               <!-- ... -->
             </rulesets>
           </configuration>
         </plugin>
       </plugins>
     </pluginManagement>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-pmd-plugin</artifactId>
       </plugin>
     </plugins>
   </build>
   
   <reporting>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-pmd-plugin</artifactId>
       </plugin>
     </plugins>
   </reporting>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to