Hi

I recently wrote an annotation processor
(javax.annotation.processing.Processor) to generate META-INF/services
files based on annotated SPI implementations.

I ran into different orders of problems building the project with
gradle, and I'd like to share a few thought about it (I also would
like to propose some pathces, but I can't get my eclipse to digest the
gradle codebase – think it is groovy eclipse plugin's fault)

I'm not sure any of the following is a bug in gradle, so I write to
the ML instead of posting to Jira


1. "compile" depends on "resources"

Processors get loaded by javac by based on the contents of any
META-INF/services/javax.annotation.processing.Processor it can find in
the compilation classpath. When you write a processor, you need to
produce a META-INF/services/javax.annotation.processing.Processor
file, but it must NOT be in the compilation classpath of your
processor (least javac thinks it should load it and complains when it
doesn't find it) – which is exactly what happens building with gradle
if the META-INF/services/javax.annotation.processing.Processor is
inside src/main/resources

Of course there are workarounds,
– one (the one I used) is to temporarily rename the
/build/classes/META-INF/services/javax.annotation.processing.Processor
file before compilation (and rename back again after that)
– another is probably to store the
javax.annotation.processing.Processor somwhere else
(/src/main/META-INF?) and instruct gradle to include it in
/build/classes after the compilation has run

I think though that either "resources" should run AFTER "compile" (but
since both grails and maven run it first there must be some good
reason I can't see for running it first) or /build/classes should not
be included in the compilation classpath


2. Ant's <javac> is too smart (or maybe I got annotation processing wrong)

Ant's <javac> task scans the source and destinarion directories before
running, and processes only the files that have been changed.
This makes it practically impossible to write any annotation processor
whcich tries to build an index out of the processed resources (since
not all resources are processed).

It could be that i got annotation processing wrong and that actually
such a processor does not respect point 1 of the Processor contract
("The result of processing a given input is not a function of the
presence or absence of other inputs (orthogonality)")...


3. There is not a "compile-only" dependency scope

Annotation processors must be in the compilation classpath but
generally they need not be in the runtime classpath (similar to
"provided" dependencies – one could argue that while "provided" deps
must be included when running tests, annotation processors should
not).
The java plugin does not provide any suitable dependency scope for
annotation processors.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to