doanduyhai / Achilles

An advanced Java Object Mapper/Query DSL generator for Cassandra
http://achilles.archinnov.info
Apache License 2.0
241 stars 92 forks source link

Gradle incremental annotation rocessing #373

Open bric3 opened 3 years ago

bric3 commented 3 years ago

Hi @doanduyhai

I'd liek to propose the following enhancement: Gradle supports incremental annotation processing, meaning the annotation processor won't have to run on every new compilation.

For that there is a simple guide to follow there to make sure the annotation processor is eligible to incremental annotation processing: https://docs.gradle.org/current/userguide/java_plugin.html#sec:incremental_annotation_processing

If I'm not mistaken achilles core is ok with these points :

I believe this annotation processor falls aggregatig category as it reaches to other elements like codecs or compiler registry. I followed the specific constraints :

"Aggregating" processors have the following limitations:

The changes looks to be minimal.

If possible it would be great to backport this change to the 5.3.x line.

Thank you in advance for the consideration.

doanduyhai commented 3 years ago

Thanks for the PR @bric3

Unfortunately, Achilles processor cannot be incremental for several reasons:

1) It does not use the Filer API. Instead it is using com.squareup.javapoet.JavaFile to generate the source classes: https://github.com/doanduyhai/Achilles/blob/master/achilles-core/src/main/java/info/archinnov/achilles/internals/apt/processors/meta/AchillesProcessor.java#L118-L162

2) It does relies on internal Sun compiler classes to parse nested structures like Map<String, @Frozen MyUDT>: https://github.com/doanduyhai/Achilles/blob/b85a7f9b5e6415000787b833cdb3aa85c01ff660/achilles-core/src/main/java/info/archinnov/achilles/internals/parser/AnnotationTree.java#L274-L300

At that time, this was the only solution to parse nested annotations inside generic types. I don't know if since then things have improved on the front of Java annotation processor to avoid using internal classes. If so I'll be happy to refactor this part of the code to get rid of the Sun internal classes

bric3 commented 3 years ago

Oh I missed those 😅.

I have seen other annotation processors using JavaPoet and activating Gradle's incremental processing. In preliminary tests this worked either in isolating and aggregating modes, but the model don't rely on UDT. Maybe I was mislead.

Thanks for the quick feedback and the consideration of this feature!

doanduyhai commented 3 years ago

My bad. The code https://github.com/doanduyhai/Achilles/blob/master/achilles-core/src/main/java/info/archinnov/achilles/internals/apt/processors/meta/AchillesProcessor.java#L118-L162 still uses the Filer API in the end. It is just handled by com.squareup.javapoet.JavaFile class itself: https://github.com/square/javapoet/blob/8ebce31cd655cf181ebdde59dcf04c50cbda7264/src/main/java/com/squareup/javapoet/JavaFile.java#L164

However the 2nd issue still remains, if I stop using Sun javac internal class, it will break all support of nested annotations