ascheman commented on issue #1085:
URL:
https://github.com/apache/maven-compiler-plugin/issues/1085#issuecomment-5017025358
Digging deeper before proposing a patch — this turns out to be more of a
design trade-off than a plain bug, so I'd like your steer before opening a PR.
**What actually happens:** when `proc` is unset the plugin passes no `-proc`
option (`Options.addComaSeparated` skips a `null` value), so `javac`'s own
version-dependent default applies — `-proc:full` before Java 23, `-proc:none`
(unless processors are configured) from Java 23 on.
On **JDK < 23** with `-proc:full`, `javac` discovers annotation processors
on the **regular compile classpath** (the classic
Lombok-as-a-plain-`<dependency>` setup, no `annotationProcessorPaths`). In that
case a processor really does run and `rebuild-on-change` is *correct*.
`hasAnnotationProcessor()` can't tell that apart from "no processor at all"
without inspecting the classpath, so it conservatively returns `true`. That's
**safe but pessimistic**: a project with genuinely no processor (e.g. a plain
test module) recompiles the whole source set on any change, which contradicts
the documented default ("only the modified source files will be recompiled").
So the current behaviour isn't wrong — it just can't distinguish the two
cases. Two ways forward:
1. **Detect the actual processor.** Scan `annotationProcessorPaths` (always)
and, when `-proc:full` is in effect, the compile classpath too, for
`META-INF/services/javax.annotation.processing.Processor`; drive
`hasAnnotationProcessor()` off that. No behaviour change, per-file incremental
whenever no processor is really present. Costs an IO scan (cacheable).
2. **Document the conservatism.** Keep the behaviour and note in the
`incrementalCompilation` default javadoc that on JDK < 23 with `proc` unset the
plugin assumes a processor may be present (because `javac` defaults to
`-proc:full` and discovers classpath processors), and that `proc=none` or an
explicit `incrementalCompilation` restores per-file.
(Forcing `-proc:none` by default when nothing is declared would align JDK <
23 with 23+, but it would stop classpath-discovered processors from running on
JDK < 23 — a breaking change, even if `javac` already deprecates that pattern
on 21+. So I'd rule that out.)
I've pushed an IT that reproduces the pessimistic case; it's happy to be
narrowed to the provably-no-processor scenario for whichever direction you
prefer. cc @desruisseaux, since this is your incremental-compilation code —
which of (1)/(2) (or something else) would you accept?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]