micronaut-core: Incremental annotation processor lists many originating elements for subclasses, causing full compilation.

Steps to Reproduce

  1. Clone https://github.com/nhoughto/incrementalAnnotationTesting
  2. Run gradlew compileJava -i
  3. Change MySubClass.java
  4. Re-run gradlew compileJava -i

Expected Behaviour

Incremental compilation works and MySubClass is recompiled

Actual Behaviour

Gradle full recompilation is triggered as $$MySubClassDefinitionClass has multiple originating classes.

> Task :compileJava
Caching disabled for task ':compileJava' because:
  Build cache is disabled
Task ':compileJava' is not up-to-date because:
  Input property 'stableSources' file /Users/user/Desktop/incrementalAnnotationTesting/src/main/java/test/MySubClass.java has changed.
Created classpath snapshot for incremental compilation in 0.041 secs. 1 duplicate classes found in classpath (see all with --debug).
Class dependency analysis for incremental compilation took 0.013 secs.
Full recompilation is required because the generated type 'test.$MySubClassDefinitionClass' must have exactly one originating element, but had 2. Analysis took 0.062 secs.
Compiling with JDK Java compiler API.
Note: Creating bean classes for 3 type elements
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 1.409 secs.

It appears that super classes are considered as originating classes if they are handled by micronaut annotation processor, in the given example if you remove the @Inject from MyClass.java then Micronaut doesn’t have to create the $$.. classes and incremental compilation works as expected, with just MySubClass.java being built. This extends to 3rd party / upstream Micronaut classes too, like io.micronaut.management.health.indicator.AbstractHealthIndicator. I hope this is not expected behaviour 🤞 as it would make it very difficult to get the benefits of incremental compilation with a project of any real complexity (can’t use inheritance!?)

Environment Information

  • Operating System: macOS
  • Micronaut Version: 2.3.3
  • JDK Version: Java 14

Example Application

https://github.com/nhoughto/incrementalAnnotationTesting

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I was infact missing -parameters! although not because of the gradle plugin bug, i never even knew there was a gradle plugin, so might look into moving to that, i just didn’t realise -parameters was required, as its not documented in the help docs? https://docs.micronaut.io/snapshot/guide/index.html#incrementalannotationgradle

working now either way 💪

unfortunately that is life we have to often deal with different systems and sometimes it is easier to place a hack then fight for change in some system beyond your control