The question seems to be obvious, but the implementation is pretty hard for me.
My goal is to write Ant build script to compile some classes that require another classes generated by Annotation Processor.
I have a custom annotations and it's processor implementation (inherited from AbstractProcessor
class).
As I understand I need to:
The code (step 1 & 2):
<target name="compileAnnotationProcessor">
<javac destdir="${OUTPUT_DIR}"
debug="true"
failonerror="true"
includeantruntime="false"
classpath="${java.class.path}">
<src>
<pathelement path="${PROJECT_DIR}/tools/src"/>
</src>
<include name="/path/to/annotation/processor/package/**"/>
</javac>
</target>
<target name="generateFilesWithAPT" depends="compileAnnotationProcessor">
<javac destdir="${OUTPUT_DIR}"
includeantruntime="false"
listfiles="false"
fork="true"
debug="true"
verbose="true">
<src>
<pathelement path="${PROJECT_DIR}/common/src/"/>
</src>
<include name="/path/to/files/to/compile/**"/>
<classpath>
<pathelement path="${OUTPUT_DIR}"/>
<pathelement path="${java.class.path}"/>
</classpath>
<compilerarg line="-proc:only"/>
<compilerarg line="-processorpath ${OUTPUT_DIR}/path/to/annotation/processor/package/annProcessorImplement"/>
</javac>
</target>
Actually, the first task is performing good and compiles the .class file for the Annotation processor implementation. It is stopping at 2nd task.
Ant says: Annotation processing without compilation requested but no processors were found.
What am I doing wrong?
Maybe I should put the annotation processor class in a .jar
? Or provide a file name with .class extension as -processorpath
argument?
I tried several options but nothing helps..
Notes:
I'm using ant javac
task instead of apt
one because documentation claims that apt tool as well as com.sun.mirror
API is deprecated.
I've also looked through this question, but there is no information how to compile the processor in right way.
I'm using:
Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors -> Enable Annotation Processing.
The annotation processing is done in multiple rounds. Each round starts with the compiler searching for the annotations in the source files and choosing the annotation processors suited for these annotations. Each annotation processor, in turn, is called on the corresponding sources.
The JDT-APT project provides plugins that add Java 5 annotation processing support to Eclipse. A Java annotation processor is a compiler plug-in that can gather information about source code as it is being compiled, generate additional Java types or other resource files, and post warnings and errors.
Annotation processing is a tool built into javac for scanning and processing annotations at compile time. It can create new source files; however, it can't modify existing ones. It's done in rounds. The first round starts when the compilation reaches the pre-compile phase.
My usual approach is:
Then wherever you have a dependency on your annotations, the annotation processor will be picked up automatically without any additional configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With