ascheman opened a new issue, #1085: URL: https://github.com/apache/maven-compiler-plugin/issues/1085
### Summary With the default incremental configuration and **no annotation processor** on the classpath, changing a single source file recompiles the **entire** source set instead of only the modified file, on **JDK < 23**. This contradicts the documented default and defeats incremental compilation for the common edit→compile loop on the JDK 17 / 21 LTS releases. ### Documented behaviour `AbstractCompilerMojo#incrementalCompilation` javadoc, "Default value": > If there is no annotation processor, then the default is `options,dependencies,sources`. It means that a full rebuild will be done if the compiler options or the dependencies changed, or if a source file has been deleted. **Otherwise, only the modified source files will be recompiled.** ### Actual behaviour On JDK < 23 with `proc` unset and no annotation processor present, any single-file change logs ``` [INFO] Recompiling all files because at least one source file changed. ``` and recompiles the whole source set. ### Root cause `AbstractCompilerMojo#hasAnnotationProcessor()` returns `true` unconditionally when `proc` is unset and the running JDK is older than 23 (because `javac` defaulted to `-proc:full` before Java 23). `amendincrementalCompilation()` then adds `rebuild-on-add,rebuild-on-change` to the default, forcing a full rebuild — even though **no** annotation processor is actually on the classpath. On JDK 23+ the same method checks for real processor paths (`PROCESSOR_CLASSES` / `PROCESSOR_MODULES`) and correctly returns `false`, so the default behaves per-file. ### Reproduction Minimal project: 3 independent classes, no dependencies, compiler-plugin default config. Full `compile`, change one class, `compile` again — count recompiled `.class` files: | JDK | property | result | |-----|----------|--------| | 21 | *(default)* | recompiles all 3 | | 21 | `-Dmaven.compiler.proc=none` | recompiles 1 | | 21 | `-Dmaven.compiler.incrementalCompilation=sources` | recompiles 1 | | 25 | *(default)* | recompiles 1 | Note: on the released **Maven 4.0.0-rc-5** runtime the incremental state is not persisted at all, so every `compile` is a full rebuild regardless of these settings. This reproduces on the `maven-4.0.x` / `master` SNAPSHOT lines (i.e. rc-6+), tested against `maven-compiler-plugin` `master` (`4.0.0-beta-5-SNAPSHOT`). ### Expected fix When `proc` is unset, gate the `hasAnnotationProcessor()` result on the presence of actual processor paths on **all** JDKs, not only JDK 23+. If no processor will run, a pre-23 `-proc:full` default still produces no generated files, so per-file incremental is safe — matching the documented default. ### Regression test I have an invoker IT (`incremental-default-no-processor`: three independent classes, default config, modify one between two `compile` invocations, assert only one file is recompiled). It is **red on JDK < 23** and **green on JDK 23+** before the fix, and green on all JDKs after. Happy to open a PR with the IT plus the fix. -- 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]
