Setup Java 6 annotation processing configuration for eclipse compiler with maven

前端 未结 3 399
囚心锁ツ
囚心锁ツ 2021-01-31 05:59

What\'s the best way to setup the eclipse project compiler configuration for Java 6 annotation processors?

My solution is to setup the org.eclipse.jdt.apt.core.pre

相关标签:
3条回答
  • 2021-01-31 06:07

    Update: You could try using the apt-maven-plugin. It currently provides three goals:

    • apt-process Executes apt on project sources.
    • apt:test-process Executes apt on project test sources.
    • apt:eclipse Generates Eclipse files for apt integration.

    You can configure the goals to run as part of your build as follows:

    <build>
      ...
      <plugins>
        ...
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>apt-maven-plugin</artifactId>
          <version>1.0-alpha-2</version>
          <executions>
            <execution>
              <goals>
                <goal>process</goal>
                <goal>test-process</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        ...
      </plugins>
      ...
    </build>
    

    By default the output directory is set to ${project.build.directory}/generated-sources/apt,

    There is an open Jira against the compiler plugin to add APT support for Java 6, you can go and vote for it if this is something you want to to see in future versions.

    0 讨论(0)
  • 2021-01-31 06:17

    There is a simpler solution in Eclipse Juno (I'm not sure about previous versions). In Preferences / Maven / Annotation Processing there are three modes for annotation processing. It is disabled by default, but I've tested both other options and worked like a charm for me. This way, you don't need to configure APT processing for every project or modify its pom.xml.

    0 讨论(0)
  • 2021-01-31 06:21

    I am using http://code.google.com/p/maven-annotation-plugin/ wich is simpler to configure. You can use it in two ways:

    • generate sources during compilation (configuration below)
    • generate sources "by hand" to src/main/generated and keep them on SCM
           <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <compilerArguments>-encoding ${project.build.sourceEncoding}</compilerArguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
    
    
           <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <executions>
                    <execution>
                        <id>process-test</id>
                        <goals>
                            <goal>process-test</goal>
                        </goals>
                        <phase>generate-test-sources</phase>
                        <configuration>
                            <compilerArguments>-encoding ${project.build.sourceEncoding}</compilerArguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
    
          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <!-- Disable annotation processors during normal compilation -->
                    <compilerArgument>-proc:none</compilerArgument>
                </configuration>
            </plugin>
    
    0 讨论(0)
提交回复
热议问题