From https://github.com/pmd/pmd-eclipse-plugin/issues/12
This plugin relies on .ruleset file available inside workspace plugin directory.
In Mac this is /<path>/.metadata/.plugins/net.sourceforge.pmd.eclipse.plugin/ruleset.xml
In our case, workspace files are not checked in to GIT. So we need to rely on the ruleset file from the source code.
Problem is the ruleset file (.pmd.xml) file relative to workspace is not picked up. This file is defined in
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.6</version>
<configuration>
<includeTests>false</includeTests>
<minimumTokens>100</minimumTokens>
<linkXref>true</linkXref>
<rulesets>
<ruleset>${project.basedir}/.pmd.xml</ruleset>
</rulesets>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
Question:
How can this file (.pmd.xml) be fed to pmd eclipse plugin automatically. We want PMD plugin to use only this file and not the default ones that come with the plugin.
Interestingly, exclude patterns mentioned in this file is picked up but not the rules.
Note:
I can still achieve this by going to Preferences -> PMD -> Rule Configuration -> Use Global RuleManagement -> Delete all rules -> import all rules using the file '.pmd.xml'
This requires developers to do this step every time they create a workspace.
Not sure if this is related to PULL https://github.com/pmd/pmd/pull/36
I've tried it with maven and eclipse - not sure, which build tools you actually use, as you are mentioning a "build.properties" file...
Attached is a sample project (bug-1472.zip).
mvn clean verify.pmdruleset.xmlfile which contains the rules from your.pmd.xmlfile..pmdfile, which stores the configuration of the pmd-eclipse plugin..classpath,.project,.settings/)Foo.javashould have a violation highlighted ("Avoid using if statements without curly braces")Can you verify, that this works for you? If not, double check
Especially the m2e-code-quality plugins are important, as they take the configuration from the maven pom.xml file and configure the pmd-eclipse plugin accordingly and automatically.
Now, depending on what rules you have in your custom
.pmd.xmlfile, there might be a problem with the "Global Rule Management": If the rules you want to use are not checked in the global rule management, they will be ignored. So, you'll either need to disable the "global rule management" or do, what you have described (import your own custom rule set there).If this is your problem, then you are dealing with this bug: https://sourceforge.net/p/pmd/bugs/1163/
Last edit: Andreas Dangel 2016-05-28