@@ -74,7 +74,7 @@ public class JoobyProcessor extends AbstractProcessor {
7474
7575 if (incremental ) {
7676 // enables incremental annotation processing support in Gradle
77- options .add ("org.gradle.annotation.processing.isolating " );
77+ options .add ("org.gradle.annotation.processing.aggregating " );
7878 }
7979
8080 return options ;
@@ -93,7 +93,7 @@ public class JoobyProcessor extends AbstractProcessor {
9393 this .processingEnv = processingEnvironment ;
9494
9595 debug = boolOpt (processingEnv , OPT_DEBUG , false );
96- incremental = boolOpt (processingEnv , OPT_INCREMENTAL , false );
96+ incremental = boolOpt (processingEnv , OPT_INCREMENTAL , true );
9797
9898 debug ("Incremental annotation processing is turned %s." , incremental ? "ON" : "OFF" );
9999 }
@@ -193,7 +193,7 @@ private void build(Filer filer) throws Exception {
193193 }
194194 }
195195
196- List < String > moduleList = new ArrayList <>();
196+ Map < TypeElement , String > modules = new LinkedHashMap <>();
197197 for (Map .Entry <TypeElement , List <HandlerCompiler >> entry : classes .entrySet ()) {
198198 TypeElement type = entry .getKey ();
199199 String typeName = typeUtils .erasure (type .asType ()).toString ();
@@ -204,14 +204,10 @@ private void build(Filer filer) throws Exception {
204204 onClass (moduleClass , moduleBin );
205205 writeClass (filer .createClassFile (moduleClass , type ), moduleBin );
206206
207- moduleList . add ( moduleClass );
207+ modules . put ( type , moduleClass );
208208 }
209209
210- if (!incremental ) {
211- // writing resource files would prevent incremental annotation processing in Gradle:
212- // https://docs.gradle.org/5.0/userguide/java_plugin.html#sec:incremental_annotation_processing
213- doServices (filer , moduleList );
214- }
210+ doServices (filer , modules );
215211 }
216212
217213 private String signature (ExecutableElement method ) {
@@ -244,12 +240,14 @@ private void debug(String format, Object... args) {
244240 }
245241 }
246242
247- private void doServices (Filer filer , List < String > moduleList ) throws IOException {
243+ private void doServices (Filer filer , Map < TypeElement , String > modules ) throws IOException {
248244 String location = "META-INF/services/" + MvcFactory .class .getName ();
245+ Element [] originatingElements = modules .keySet ().toArray (new Element [0 ]);
249246 debug ("%s" , location );
250- FileObject resource = filer .createResource (StandardLocation .CLASS_OUTPUT , "" , location );
247+ FileObject resource = filer .createResource (StandardLocation .CLASS_OUTPUT , "" , location , originatingElements );
251248 StringBuilder content = new StringBuilder ();
252- for (String classname : moduleList ) {
249+ for (Map .Entry <TypeElement , String > e : modules .entrySet ()) {
250+ String classname = e .getValue ();
253251 debug (" %s" , classname );
254252 content .append (classname ).append (System .getProperty ("line.separator" ));
255253 }
0 commit comments