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:
- Compile the Annotation Processor
- Run the compiler over some annotated classes to generate the new ones.
- Compile the classes that require generated classes
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:
- Java 1.6
- Ant 1.8.2