Uploaded image for project: 'Tools (JBoss Tools)'
  1. Tools (JBoss Tools)
  2. JBIDE-8208

Improve how annotation processors are setup/detected via maven/m2eclipse

XMLWordPrintable

    • Hide
      With m2e-apt, you can now automatically enable annotation processing support for maven projects, based on their classpath dependencies (Requires Java >= 1.6).

      m2e-apt supports both annotation processing set on the maven-compiler-plugin or the maven-processor-plugin(http://code.google.com/p/maven-annotation-plugin/) (the latter takes precedence over the former).

      For example, to enable the JPA modelgen annotation processor, you can either set :

      <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.4</version>
          <configuration>
              <source>1.6</source>
              <target>1.6</target>
          </configuration>
          <dependencies>
              <dependency>
                  <groupId>org.hibernate</groupId>
                  <artifactId>hibernate-jpamodelgen</artifactId>
                  <version>1.2.0.Final</version>
              </dependency>
          </dependencies>
      </plugin>

      or

      <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.4</version>
          <configuration>
              <source>1.6</source>
              <target>1.6</target>
              <compilerArgument>-proc:none</compilerArgument>
          </configuration>
      </plugin>
      <plugin>
          <groupId>org.bsc.maven</groupId>
          <artifactId>maven-processor-plugin</artifactId>
          <version>2.0.5</version>
          <executions>
              <execution>
                  <id>process</id>
                  <goals>
                      <goal>process</goal>
                  </goals>
                  <phase>generate-sources</phase>
              </execution>
          </executions>
          <dependencies>
              <dependency>
                  <groupId>org.hibernate</groupId>
                  <artifactId>hibernate-jpamodelgen</artifactId>
                  <version>1.2.0.Final</version>
              </dependency>
          </dependencies>
      </plugin>


      The generated source folders (target/generated-sources/annotation for maven-compiler-plugin; target/generated-sources/apt for maven-processor-plugin) are automatically added to the project classpath.

      Since Annotation Processing is managed by Eclipse JDT APT by default, a change in your source classes triggers incremental processing automatically. The downside of using JDT APT is, there's no separation between main and test classes (the way maven-processor-plugin handles them). To mitigate that limitation, you can change the workspace or project preferences to delegate annotation processing to maven, instead of JDT APT (Note this only works when using maven-processor-plugin). This will result in slower incremental builds (all classes will be processed) but will provide identical results to maven command line builds.

      Automatic Annotation Processing configuration from the maven pom.xml can also be disabled altogether. In this case, your manual settings for Eclipse JDT APT will remain untouched.

      Go to Window > Preferences > Maven > Annotation processing or right-click on your project > Properties > Maven > Annotation processing to select the Annotation Processing strategy of your choice.

      Show
      With m2e-apt, you can now automatically enable annotation processing support for maven projects, based on their classpath dependencies (Requires Java >= 1.6). m2e-apt supports both annotation processing set on the maven-compiler-plugin or the maven-processor-plugin( http://code.google.com/p/maven-annotation-plugin/ ) (the latter takes precedence over the former). For example, to enable the JPA modelgen annotation processor, you can either set : <plugin>     <artifactId>maven-compiler-plugin</artifactId>     <version>2.4</version>     <configuration>         <source>1.6</source>         <target>1.6</target>     </configuration>     <dependencies>         <dependency>             <groupId>org.hibernate</groupId>             <artifactId>hibernate-jpamodelgen</artifactId>             <version>1.2.0.Final</version>         </dependency>     </dependencies> </plugin> or <plugin>     <artifactId>maven-compiler-plugin</artifactId>     <version>2.4</version>     <configuration>         <source>1.6</source>         <target>1.6</target>         <compilerArgument>-proc:none</compilerArgument>     </configuration> </plugin> <plugin>     <groupId>org.bsc.maven</groupId>     <artifactId>maven-processor-plugin</artifactId>     <version>2.0.5</version>     <executions>         <execution>             <id>process</id>             <goals>                 <goal>process</goal>             </goals>             <phase>generate-sources</phase>         </execution>     </executions>     <dependencies>         <dependency>             <groupId>org.hibernate</groupId>             <artifactId>hibernate-jpamodelgen</artifactId>             <version>1.2.0.Final</version>         </dependency>     </dependencies> </plugin> The generated source folders (target/generated-sources/annotation for maven-compiler-plugin; target/generated-sources/apt for maven-processor-plugin) are automatically added to the project classpath. Since Annotation Processing is managed by Eclipse JDT APT by default, a change in your source classes triggers incremental processing automatically. The downside of using JDT APT is, there's no separation between main and test classes (the way maven-processor-plugin handles them). To mitigate that limitation, you can change the workspace or project preferences to delegate annotation processing to maven, instead of JDT APT (Note this only works when using maven-processor-plugin). This will result in slower incremental builds (all classes will be processed) but will provide identical results to maven command line builds. Automatic Annotation Processing configuration from the maven pom.xml can also be disabled altogether. In this case, your manual settings for Eclipse JDT APT will remain untouched. Go to Window > Preferences > Maven > Annotation processing or right-click on your project > Properties > Maven > Annotation processing to select the Annotation Processing strategy of your choice.
    • Not Required

      Any way m2eclipse can setup and detect annotation processors ?

      Why isn't annotation processor not enabled by default when generating the .settings files for it ?

          There are no Sub-Tasks for this issue.

              fbricon@redhat.com Fred Bricon
              manderse@redhat.com Max Andersen
              Isaac Rooskov Isaac Rooskov (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: