Skip to content

Instantly share code, notes, and snippets.

@xhanin
Created April 7, 2014 19:42
Show Gist options
  • Save xhanin/10038267 to your computer and use it in GitHub Desktop.
Save xhanin/10038267 to your computer and use it in GitHub Desktop.
Java Annotation Processing Notes

A few notes on java annotation processing, collected when working on RESTX annotation processor.

Don't register multiple annotation processor on same annotation.

It fails silently.

Disable annotation processing in module defining an annotation processor.

Use -proc:none javac option. In restx build you can use this fragment: classpath:///restx/build/fragments/maven/annotation-processing-disable.xml

Never let exceptions escape your methods in your annotation processor

javac will silently stop the compilation

Passing options to annotation processor

with javac, use -A<option> Example: -Adebug

In IDEA it’s in compiler preferences: https://cloudup.com/cdAuvh0Mz7z In Maven it’s in the compiler plugin: http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html

Note that -Adebug is not a standard option, but it's the option used by RESTX annotation processors to provide more details.

Base processor in RESTX, helping to fulfill these requirements

https://github.com/restx/restx/blob/master/restx-common/src/main/java/restx/common/processor/RestxAbstractProcessor.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment