title: Maven 3 - How to add annotation processor dependency?
body: <p>I need to run an annotation processor on my project's sources. The annotation processor should not become a transitive dependency of the project since it's only needed for annotation processing and nothing else.</p>
  
  <p>Here is the complete (non-working) test pom I use for this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&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/maven-v4_0_0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;test&lt;/groupId&gt;
    &lt;artifactId&gt;test&lt;/artifactId&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;Test annotations&lt;/name&gt;
    &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;hibernate-jpamodelgen.version&gt;1.2.0.Final&lt;/hibernate-jpamodelgen.version&gt;
    &lt;/properties&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;javax&lt;/groupId&gt;
        &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
        &lt;version&gt;6.0&lt;/version&gt;
        &lt;scope&gt;provided&lt;/scope&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.0&lt;/version&gt;
          &lt;configuration&gt;
            &lt;annotationProcessors&gt;
              &lt;annotationProcessor&gt;
                org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor&lt;/annotationProcessor&gt;
            &lt;/annotationProcessors&gt;
            &lt;debug&gt;true&lt;/debug&gt;
            &lt;optimize&gt;true&lt;/optimize&gt;
            &lt;source&gt;1.6&lt;/source&gt;
            &lt;target&gt;1.6&lt;/target&gt;
            &lt;compilerArguments&gt;
              &lt;AaddGeneratedAnnotation&gt;true&lt;/AaddGeneratedAnnotation&gt;
              &lt;Adebug&gt;true&lt;/Adebug&gt;
            &lt;/compilerArguments&gt;
          &lt;/configuration&gt;
          &lt;dependencies&gt;
            &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpamodelgen&lt;/artifactId&gt;
              &lt;version&gt;${hibernate-jpamodelgen.version}&lt;/version&gt;
            &lt;/dependency&gt;
          &lt;/dependencies&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>I explicitly defined <code>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</code> as an annotation processor in the plugin configuration for tests and I know it shouldn't be required.</p>
  
  <p>The problem I'm encountering is that the <code>hibernate-jpamodelgen</code> dependency is not added to the compiler classpath so the annotation processor is not found and the build fails.</p>
  
  <p>As per this <a href="https://stackoverflow.com/a/11245730/1030527">answer</a>, I tried adding the dependency as a build extension (not sure I understand what those are supposed to be!) like so:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;extensions&gt;
    &lt;extension&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-jpamodelgen&lt;/artifactId&gt;
      &lt;version&gt;${hibernate-jpamodelgen.version}&lt;/version&gt;
    &lt;/extension&gt;
  &lt;/extensions&gt;
  </code></pre>
  
  <p>This also doesn't add <code>hibernate-jpamodelgen</code> to the compiler classpath.</p>
  
  <p>The only thing I found which works so far is adding the dependency to the project in the <code>&lt;dependencies&gt;</code> section. This has the unfortunate side-effect of adding <code>hibernate-jpamodelgen</code> as a transitive dependency afterwards which I want to avoid.</p>
  
  <p>My previous working setup uses the <code>maven-processor-plugin</code> plugin to achieve what I want. However, this plugin is not supported by eclipse m2e and the latest version of the <code>maven-compiler-plugin</code> now handles multiple compiler arguments properly so I'd rather use the latter.</p>