Skip to content

Gradle incremental annotation processing metadata support#6999

Open
lihaoyi wants to merge 27 commits intocom-lihaoyi:mainfrom
lihaoyi:incremental-annotation-processing
Open

Gradle incremental annotation processing metadata support#6999
lihaoyi wants to merge 27 commits intocom-lihaoyi:mainfrom
lihaoyi:incremental-annotation-processing

Conversation

@lihaoyi
Copy link
Copy Markdown
Member

@lihaoyi lihaoyi commented Apr 12, 2026

Vibe Coded, resolves #6991

Overview

This PR adds incremental annotation-processing support to Mill for Java/Zinc compilation by consuming Gradle-compatible processor metadata from META-INF/gradle/incremental.annotation.processors.

Example contents:

org.mapstruct.ap.MappingProcessor,isolating

Another example with multiple processors:

com.google.auto.service.processor.AutoServiceProcessor,aggregating
dagger.internal.codegen.ComponentProcessor,isolating

Common kind values:

  • isolating
  • aggregating
  • dynamic

Mill now detects active annotation processors, reads their incremental mode (isolating, aggregating, dynamic), and usesthat to improve incremental cleanup of generated outputs. For supported processors, Mill tracks non-analysis outputs produced under compile.dest/classes, removes stale generated files when their originating source is deleted, and informs Zinc about those removed products so downstream invalidation remains correct. Processor kind parsing is case-insensitive, so jars that declare ISOLATING/AGGREGATING also work. If active processors do not declare supported incremental metadata, Mill falls back to non-incremental compilation rather than risking stale outputs.

Implementation

Zinc does not have any support for incremental annotation processing at all, so we have to do it ourselves by subclassing the Javac compiler and instrumenting the methods we care about. Javac is modular and composed of a bunch of separate objects, so we have to subclass each one and assemble them together ourselves

This does two things:

  1. Lets us extract the information we need to track which generated java file, classfile, or resource came from annotation processing which source file

  2. Lets us intercept the actual annotation processing execution, such that we can use the information extracted above to selectively run or not-run annotation processors on various parts of the codebase

Testing

The PR also adds an unit test suite covering both processor categories with real libraries listed in Gradle’s incremental annotation processor docs:

  • MapStruct as an isolating processor
  • AutoService as an aggregating processor
  • A regression test for Dagger to confirm uppercase metadata markers are handled correctly.
  • Various other scenarios with incremental annotation processing (editing a file, removing other files, etc.)

@lihaoyi lihaoyi force-pushed the incremental-annotation-processing branch from 43aec84 to c74b4e6 Compare April 12, 2026 06:48
@lihaoyi lihaoyi force-pushed the incremental-annotation-processing branch from 16b58d0 to 7ea334e Compare April 12, 2026 07:12
@lihaoyi lihaoyi changed the title Incremental annotation processing support Gradle incremental annotation processing metadata support Apr 12, 2026
@lihaoyi lihaoyi force-pushed the incremental-annotation-processing branch from 577e80d to 4bf658e Compare April 12, 2026 11:53
@lihaoyi lihaoyi force-pushed the incremental-annotation-processing branch from 609afa3 to 88641fe Compare April 12, 2026 12:28
@lihaoyi lihaoyi force-pushed the incremental-annotation-processing branch from a8d404c to c75b749 Compare April 12, 2026 12:51
@lihaoyi lihaoyi force-pushed the incremental-annotation-processing branch from fe985bd to 01cd37b Compare April 12, 2026 13:10
@lihaoyi lihaoyi force-pushed the incremental-annotation-processing branch from 282a841 to 80c706e Compare April 12, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JavaModule] Stale .class files survive incremental compilation when source files are deleted

1 participant