Menu

#1472 [eclipse] ruleset file .pmd.xml is not picked up

Eclipse-Plugin
more-info-needed
None
Eclipse
3-Major
Bug
2017-01-27
2016-04-27
No

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

  • build.properties (maven.pmd.rulesetfiles = ${basedir}/.pmd.xml)
  • pom.xml
<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

Discussion

  • Andreas Dangel

    Andreas Dangel - 2016-05-28
    • status: open --> more-info-needed
    • assigned_to: Andreas Dangel
     
  • Andreas Dangel

    Andreas Dangel - 2016-05-28

    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).

    1. unzip it
    2. make sure, it compiles on the command line: mvn clean verify
    3. in eclipse, select: File -> Import... -> Maven -> Existing Maven Projects
      • If you don't see this option, then you are missing the "m2e" plugin - that's needed if you want to use maven within eclipse. I think, it is usually included in eclipse by default nowadays.
    4. Once you have the project imported, everything should work. You'll see, that
      • Eclipse created a .pmdruleset.xml file which contains the rules from your .pmd.xml file.
      • It created a .pmd file, which stores the configuration of the pmd-eclipse plugin.
      • And some more files (.classpath, .project, .settings/)
      • The file Foo.java should 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.xml file, 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
  • Andreas Dangel

    Andreas Dangel - 2017-01-27
    • summary: ruleset file .pmd.xml is not picked up --> [eclipse] ruleset file .pmd.xml is not picked up
     

Log in to post a comment.

MongoDB Logo MongoDB