[jbosstools-issues] [JBoss JIRA] (JBIDE-8208) Improve how annotation processors are setup/detected via maven/m2eclipse

Fred Bricon (JIRA) jira-events at lists.jboss.org
Tue May 15 03:47:18 EDT 2012


     [ https://issues.jboss.org/browse/JBIDE-8208?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fred Bricon updated JBIDE-8208:
-------------------------------

    Release Notes Text: 
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 or 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.



  was:
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  :
{code:xml}
<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>
{code}

or 
{code:xml}
<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>
{code}

The generated source folders (target/generated-sources/annotation for maven-compiler-plugin; target/generated-sources/apt or 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 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.




    
> Improve how annotation processors are setup/detected via maven/m2eclipse
> ------------------------------------------------------------------------
>
>                 Key: JBIDE-8208
>                 URL: https://issues.jboss.org/browse/JBIDE-8208
>             Project: Tools (JBoss Tools)
>          Issue Type: Feature Request
>          Components: maven, UpStream
>            Reporter: Max Rydahl Andersen
>            Assignee: Fred Bricon
>            Priority: Blocker
>              Labels: new_and_noteworthy
>             Fix For: 3.3.0.Beta3
>
>
> 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 ?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jbosstools-issues mailing list