@@ -289,7 +289,7 @@ final Charset charset() {
289
289
* </ul>
290
290
*
291
291
* Prior Java 21, {@code full} was the default.
292
- * Starting with JDK 21, this option must be set explicitly .
292
+ * Starting with Java 21, the default is {@code none} unless another processor option is used .
293
293
*
294
294
* @see #annotationProcessors
295
295
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-proc">javac -proc</a>
@@ -363,7 +363,12 @@ final Charset charset() {
363
363
* </p>
364
364
*
365
365
* @since 3.12.0
366
+ *
367
+ * @deprecated This flag is ignored.
368
+ * Replaced by ordinary dependencies with {@code <type>} element set to
369
+ * {@code processor}, {@code classpath-processor} or {@code modular-processor}.
366
370
*/
371
+ @ Deprecated (since = "4.0.0" )
367
372
@ Parameter (defaultValue = "false" )
368
373
protected boolean annotationProcessorPathsUseDepMgmt ;
369
374
@@ -458,7 +463,7 @@ final Charset charset() {
458
463
459
464
/**
460
465
* Whether to provide more details about why a module is rebuilt.
461
- * This is used only if {@link #incrementalCompilation} is {@code "inputTreeChanges "}.
466
+ * This is used only if {@link #incrementalCompilation} is set to something else than {@code "none "}.
462
467
*
463
468
* @see #incrementalCompilation
464
469
*/
@@ -586,13 +591,23 @@ final Charset charset() {
586
591
* In all cases, the current compiler-plugin does not detect structural changes other than file addition or removal.
587
592
* For example, the plugin does not detect whether a method has been removed in a class.
588
593
*
594
+ * <h4>Default value</h4>
595
+ * The default value depends on the context.
596
+ * If there is no annotation processor, then the default is {@code "options,dependencies,sources"}.
597
+ * It means that a full rebuild will be done if the compiler options or the dependencies changed,
598
+ * or if a source file has been deleted. Otherwise, only the modified source files will be recompiled.
599
+ *
600
+ * <p>If an annotation processor is present (e.g., {@link #proc} set to a value other than {@code "none"}),
601
+ * then the default value is same as above with the addition of {@code "rebuild-on-add,rebuild-on-change"}.
602
+ * It means that a full rebuild will be done if any kind of change is detected.</p>
603
+ *
589
604
* @see #staleMillis
590
605
* @see #fileExtensions
591
606
* @see #showCompilationChanges
592
607
* @see #createMissingPackageInfoClass
593
608
* @since 4.0.0
594
609
*/
595
- @ Parameter ( defaultValue = "options,dependencies,sources" )
610
+ @ Parameter // The default values are implemented in `incrementalCompilationConfiguration()`.
596
611
protected String incrementalCompilation ;
597
612
598
613
/**
@@ -610,18 +625,30 @@ final Charset charset() {
610
625
611
626
/**
612
627
* Returns the configuration of the incremental compilation.
613
- * This method may be removed in a future version if the deprecated parameter is removed.
628
+ * If the argument is null or blank, then this method applies
629
+ * the default values documented in {@link #incrementalCompilation} javadoc.
614
630
*
615
631
* @throws MojoException if a value is not recognized, or if mutually exclusive values are specified
616
632
*/
617
633
final EnumSet <IncrementalBuild .Aspect > incrementalCompilationConfiguration () {
618
- if (useIncrementalCompilation != null ) {
619
- return useIncrementalCompilation
620
- ? EnumSet .of (
621
- IncrementalBuild .Aspect .DEPENDENCIES ,
622
- IncrementalBuild .Aspect .SOURCES ,
623
- IncrementalBuild .Aspect .REBUILD_ON_ADD )
624
- : EnumSet .of (IncrementalBuild .Aspect .CLASSES );
634
+ if (incrementalCompilation == null || incrementalCompilation .isBlank ()) {
635
+ if (useIncrementalCompilation != null ) {
636
+ return useIncrementalCompilation
637
+ ? EnumSet .of (
638
+ IncrementalBuild .Aspect .DEPENDENCIES ,
639
+ IncrementalBuild .Aspect .SOURCES ,
640
+ IncrementalBuild .Aspect .REBUILD_ON_ADD )
641
+ : EnumSet .of (IncrementalBuild .Aspect .CLASSES );
642
+ }
643
+ var aspects = EnumSet .of (
644
+ IncrementalBuild .Aspect .OPTIONS ,
645
+ IncrementalBuild .Aspect .DEPENDENCIES ,
646
+ IncrementalBuild .Aspect .SOURCES );
647
+ if (hasAnnotationProcessor ()) {
648
+ aspects .add (IncrementalBuild .Aspect .REBUILD_ON_ADD );
649
+ aspects .add (IncrementalBuild .Aspect .REBUILD_ON_CHANGE );
650
+ }
651
+ return aspects ;
625
652
} else {
626
653
return IncrementalBuild .Aspect .parse (incrementalCompilation );
627
654
}
@@ -1502,6 +1529,44 @@ final void resolveProcessorPathEntries(Map<PathType, List<Path>> addTo) throws M
1502
1529
}
1503
1530
}
1504
1531
1532
+ /**
1533
+ * {@return whether an annotation processor seems to be present}.
1534
+ * This method is invoked if the user did not specified explicit incremental compilation options.
1535
+ *
1536
+ * @see #incrementalCompilation
1537
+ */
1538
+ private boolean hasAnnotationProcessor () {
1539
+ if ("none" .equalsIgnoreCase (proc )) {
1540
+ return false ;
1541
+ }
1542
+ if (proc == null || proc .isBlank ()) {
1543
+ /*
1544
+ * If the `proc` parameter was not specified, its default value depends on the Java version.
1545
+ * It was "full" prior Java 21 and become "none if no other processor option" since Java 21.
1546
+ * Since even the full" case may do nothing, always check if a processor is declared.
1547
+ */
1548
+ if (annotationProcessors == null || annotationProcessors .length == 0 ) {
1549
+ if (annotationProcessorPaths == null || annotationProcessorPaths .isEmpty ()) {
1550
+ DependencyResolver resolver = session .getService (DependencyResolver .class );
1551
+ if (resolver == null ) { // Null value happen during tests, depending on the mock used.
1552
+ return false ;
1553
+ }
1554
+ var allowedTypes = EnumSet .of (JavaPathType .PROCESSOR_CLASSES , JavaPathType .PROCESSOR_MODULES );
1555
+ DependencyResolverResult dependencies = resolver .resolve (DependencyResolverRequest .builder ()
1556
+ .session (session )
1557
+ .project (project )
1558
+ .requestType (DependencyResolverRequest .RequestType .COLLECT )
1559
+ .pathScope (compileScope )
1560
+ .pathTypeFilter (allowedTypes )
1561
+ .build ());
1562
+
1563
+ return !dependencies .getDependencies ().isEmpty ();
1564
+ }
1565
+ }
1566
+ }
1567
+ return true ;
1568
+ }
1569
+
1505
1570
/**
1506
1571
* Ensures that the directory for generated sources exists, and adds it to the list of source directories
1507
1572
* known to the project manager. This is used for adding the output of annotation processor.
0 commit comments