0
votes

I have configured the maven pmd plugin into a maven parent pom that I use with a test project called MFactors3. When I build this tiny project using m2Eclipse in Eclipse PMD reports a good number of violations. When I build the same project from the command line PMD generates an empty violations file in the target/site folder.

My parent pom has sections taken right from the recommended maven pmd documentation. I'm not showing any of the pom material now since the plugin is being invoked and it run successfully.

Below is output from just running 'mvn pmd:pmd -X' from the command line. The configuration data looks exactly right. But no violations are detected. Why?

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-pmd-plugin:2.7.1:pmd' with basic configurator -->
[DEBUG]   (f) aggregate = false
[DEBUG]   (f) compileSourceRoots = [/Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30 /src/main/java]
[DEBUG]   (f) excludeRoots = [/Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target/generated-sources/stubs]
[DEBUG]   (f) excludes = [**/*Bean.java, **/generated/*.java]
[DEBUG]   (f) format = xml
[DEBUG]   (f) includeTests = false
[DEBUG]   (f) linkXRef = true
[DEBUG]   (f) minimumPriority = 5
[DEBUG]   (f) outputDirectory = /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target/site
[DEBUG]   (f) project = MavenProject: edu.psu.sweng497a:MFactors30:0.0.1-SNAPSHOT @ /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/pom.xml
[DEBUG]   (f) reactorProjects = [MavenProject: edu.psu.sweng497a:MFactors30:0.0.1-SNAPSHOT @ /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/pom.xml]
[DEBUG]   (f) skip = false
[DEBUG]   (f) sourceEncoding = utf-8
[DEBUG]   (f) targetDirectory = /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target
[DEBUG]   (f) targetJdk = 1.6
[DEBUG]   (f) testSourceRoots = [/Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/src/test/java]
[DEBUG]   (f) xrefLocation = /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target/site/xref
[DEBUG]   (f) xrefTestLocation = /Users/Robert/Documents/workspace-sts-3.1.0-psgv/MFactors30/target/site/xref-test
[DEBUG] -- end configuration --
[DEBUG] Preparing ruleset: rulesets/basic.xml
[DEBUG] Before: rulesets/basic.xml After: basic.xml
[DEBUG] The resource 'rulesets/basic.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'rulesets/basic.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.
[DEBUG] The resource 'rulesets/basic.xml' was found as jar:file:/Users/Robert/.m2/repository/pmd/pmd/4.3/pmd-4.3.jar!/rulesets/basic.xml.
[DEBUG] Preparing ruleset: rulesets/unusedcode.xml
[DEBUG] Before: rulesets/unusedcode.xml After: unusedcode.xml
[DEBUG] The resource 'rulesets/unusedcode.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'rulesets/unusedcode.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.
[DEBUG] The resource 'rulesets/unusedcode.xml' was found as jar:file:/Users/Robert/.m2/repository/pmd/pmd/4.3/pmd-4.3.jar!/rulesets/unusedcode.xml.
[DEBUG] Preparing ruleset: rulesets/imports.xml
[DEBUG] Before: rulesets/imports.xml After: imports.xml
[DEBUG] The resource 'rulesets/imports.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'rulesets/imports.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.
[DEBUG] The resource 'rulesets/imports.xml' was found as jar:file:/Users/Robert/.m2/repository/pmd/pmd/4.3/pmd-4.3.jar!/rulesets/imports.xml.
[WARNING] Unable to locate Source XRef to link to - DISABLED
[DEBUG] Exclusions: **/*~,**/#*#,**/.#*,**/%*%,**/._*,**/CVS,**/CVS/**,**/.cvsignore,**/RCS,**/RCS/**,**/SCCS,**/SCCS/**,**/vssver.scc,**/project.pj,**/.svn,**/.svn/**,**/.arch-ids,**/.arch-ids/**,**/.bzr,**/.bzr/**,**/.MySCMServerInfo,**/.DS_Store,**/.metadata,**/.metadata/**,**/.hg,**/.hg/**,**/.git,**/.git/**,**/BitKeeper,**/BitKeeper/**,**/ChangeSet,**/ChangeSet/**,**/_darcs,**/_darcs/**,**/.darcsrepo,**/.darcsrepo/**,**/-darcs-backup*,**/.darcs-temp-mail,**/*Bean.java,**/generated/*.java
[DEBUG] Inclusions: **/*.java
[DEBUG] Velocimacro : added #link(  href name target img position alt border width height ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #image(  img alt border width height ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #banner(  banner id ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #links(  links ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #breadcrumbs(  breadcrumbs ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #displayTree(  display item ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #menuItem(  item ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #mainMenu(  menus ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #copyright(  ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #publishDate(  position publishDate version ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[DEBUG] Velocimacro : added #poweredByLogo(  poweredBy ) : source = org/apache/maven/doxia/siterenderer/resources/default-site.vm
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
1

1 Answers

1
votes

I will answer my own question. Basically it was user error in that I removed a section of the maven-pmd-plugin configuration code from the parent pom. I did this because the example, taken from the documentation, shows custom rulesets being used. I wanted the default rulesets.

It took me a long time to realize my mistake because the plugin was running without any rulesets and not indicating any problems (shouldn't it at least WARN that no rulesets were in use?).

Here is the proper configuration elements that are needed:

<!-- Customize rulesets here -->
<rulesets>
  <ruleset>rulesets/basic.xml</ruleset>
  <ruleset>rulesets/naming.xml</ruleset>
  <ruleset>rulesets/design.xml</ruleset>
</rulesets>

I would also like to point out that these rulesets are embedded within on of the plugin jar files. You will not find them on the filesystem anywhere.