title: pmd import: Entry[import from realm ClassRealm[maven.api, parent: null]]
body: <p>I am trying to add a custom rule written in java language to the pmd maven plugin.
  I expected everything to work fine when executing pmd:check goal from IntelliJ 2016.3.2 Community Edition, but instead I get the following message.</p>
  
  <p>execute goal org.apache.maven.plugins:maven-pmd-plugin:3.9.0:pmd (pmd) on project pmd-custom-rule-use: Execution pmd of goal org.apache.maven.plugins:maven-pmd-plugin:3.9.0:pmd failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-pmd-plugin:3.9.0:pmd: java.lang.NoSuchMethodError: net.sourceforge.pmd.renderers.AbstractRenderer.(Ljava/lang/String;Ljava/lang/String;)V
  --- here goes some of my .m2 jars listings ---
  [ERROR] Number of foreign imports: 1
  [ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]</p>
  
  <p>The configuration of the plugin is</p>
  
  <pre><code>   &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-pmd-plugin&lt;/artifactId&gt;
              &lt;dependencies&gt;
                  &lt;dependency&gt;
                      &lt;groupId&gt;com.codingtogo&lt;/groupId&gt;
                      &lt;artifactId&gt;pmd-custom-rule&lt;/artifactId&gt;
                      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
                  &lt;/dependency&gt;
              &lt;/dependencies&gt;
              &lt;configuration&gt;
                  &lt;rulesets&gt;
                      &lt;ruleset&gt;/myCustomRules/myRuleSet.xml&lt;/ruleset&gt;
                  &lt;/rulesets&gt;
                  &lt;sourceEncoding&gt;utf-8&lt;/sourceEncoding&gt;
                  &lt;targetJdk&gt;1.7&lt;/targetJdk&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;**/*Bean.java&lt;/exclude&gt;
                      &lt;exclude&gt;**/generated/*.java&lt;/exclude&gt;
                  &lt;/excludes&gt;
                  &lt;excludeRoots&gt;
                      &lt;excludeRoot&gt;target/generated-sources/stubs&lt;/excludeRoot&gt;
                  &lt;/excludeRoots&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.7.0&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.7&lt;/source&gt;
                  &lt;target&gt;1.7&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>The ruleset xml file is like</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;ruleset name="My custom rules"
       xmlns="http://pmd.sf.net/ruleset/1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0    
  http://pmd.sf.net/ruleset_xml_schema.xsd"
  
  
  
  xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"&gt;
  &lt;rule name="WhileLoopsMustUseBracesRule"
        message="Avoid using 'while' statements without curly braces"
        class="com.codingtogo.WhileLoopsMustUseBracesRule"&gt;
      &lt;description&gt;
          Avoid using 'while' statements without using curly braces
      &lt;/description&gt;
      &lt;priority&gt;3&lt;/priority&gt;
  
      &lt;example&gt;
          &lt;![CDATA[
          public void doSomething() {
            while (true)
                x++;
          }
      ]]&gt;
      &lt;/example&gt;
  &lt;/rule&gt;
  &lt;/ruleset&gt;
  </code></pre>
  
  <p>The dependency of the plugin is the jar where the class referenced in the ruleset is defined. The pom configuration of that project is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0       
  http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;com.codingtogo&lt;/groupId&gt;
  &lt;artifactId&gt;pmd-custom-rule&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
  &lt;dependencies&gt;
      &lt;!-- https://mvnrepository.com/artifact/net.sourceforge.pmd/pmd --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;net.sourceforge.pmd&lt;/groupId&gt;
          &lt;artifactId&gt;pmd&lt;/artifactId&gt;
          &lt;version&gt;5.0.0&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.7.0&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.7&lt;/source&gt;
                  &lt;target&gt;1.7&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
     &lt;/build&gt;
   &lt;/project&gt;
  </code></pre>
  
  <p>And the class source code is</p>
  
  <pre><code>package com.codingtogo;
  
  import net.sourceforge.pmd.lang.java.ast.ASTWhileStatement;
  
  public class WhileLoopsMustUseBracesRule {
  public Object visit(ASTWhileStatement node, Object data) {
      System.out.println("hello world");
      return data;
  }
  }
  </code></pre>
  
  <p>If I take the dependency from my jar from the pmd maven plugin out, then it runs and produces the error
  [ERROR] Error instantiating a rule
  java.lang.ClassNotFoundException: com.codingtogo.WhileLoopsMustUseBracesRule</p>
  
  <p>and the build is successful. I pinpoint it because the initial error was an api incompatibility problem but, if I take the dependency from my jar out, then the api incompatibility error is gone.</p>
  
  <p>Thanks in advance :)</p>
  
  <p>--- EDIT [SOLVED] ---
  The problem was that I was using the wrong dependency as pointed out by @Johnco. Also, I was using the wrong classes. This is the final setup.</p>
  
  <pre><code>package com.codingtogo;
  import net.sourceforge.pmd.lang.java.ast.ASTWhileStatement;
  import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
  
  public class WhileLoopsMustUseBracesRule extends AbstractJavaRule {
      public Object visit(ASTWhileStatement node, Object data) {
          System.out.println("hello world");
          return data;
      }
  }
  </code></pre>
  
  <p>Note the extends class is now AbstractJavaRule and not AbstractRule.</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;net.sourceforge.pmd&lt;/groupId&gt;
          &lt;artifactId&gt;pmd-java&lt;/artifactId&gt;
          &lt;version&gt;6.2.0&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>