Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure the Annotation Processing API without external Jar using Maven?

I would like to use a custom annotation in my project.

How can I configure maven 3 to process my annotation. The annotation and the implementation of the AbstractProcessor class are embedded in my application.

My annotation is available only for testing (src/test/java).

State annotation :

@Target(ElementType.METHOD)
public @interface State {
  boolean success() default true;
}

TestAnnotationsProcessor :

@SupportedAnnotationTypes("com.*****.client.State")
public class TestAnnotationsProcessor extends AbstractProcessor {

  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    System.out.print("TESSST ANNOTATION");
    return true;
  }
}

I don't want to put my annotation in an external project... it will be stupid because it's really dependend of my project.

How can I do that ? Thanks.

like image 673
Sandro Munda Avatar asked Feb 03 '12 12:02

Sandro Munda


1 Answers

Could you do something like (forgive me if the syntax is a little off, I don't have my IDE handy):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin<artifactId>
  <version>2.3.2</version>
  <executions>
    <execution>
      <goals>
        <goal>testCompile</goal>
      </goals>
      <phase>test-compile</phase>
      <configuration>
        <annotationProcessors>com.******.TestAnnotationsProcessor</annotationProcessors>
        <proc>only</proc>
      </configuration>
    </execution>
  </executions>
</plugin>
like image 137
Pace Avatar answered Nov 15 '22 01:11

Pace