This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git

commit c3fc26a31d1a7dc3d98cb3d3769de32306467741
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sat Nov 1 23:16:10 2025 +0100

    Catch the case where the compilation fails because of a 
`NoClassDefFoundError`.
    It may happen when an annotation processor is present but has a dependency 
which is missing.
---
 .../java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java  | 5 +++--
 src/main/java/org/apache/maven/plugin/compiler/DiagnosticLogger.java | 2 +-
 src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java     | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java 
b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index 0978d87..60473bc 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -1368,12 +1368,13 @@ public abstract class AbstractCompilerMojo implements 
Mojo {
         if (!executor.applyIncrementalBuild(this, configuration)) {
             return;
         }
-        Exception failureCause = null;
+        Throwable failureCause = null;
         final var compilerOutput = new StringWriter();
         boolean success;
         try {
             success = executor.compile(compiler, configuration, 
compilerOutput);
-        } catch (Exception e) {
+        } catch (Exception | NoClassDefFoundError e) {
+            // `NoClassDefFoundError` may happen if a dependency of an 
annotation processor is missing.
             success = false;
             failureCause = e;
         }
diff --git 
a/src/main/java/org/apache/maven/plugin/compiler/DiagnosticLogger.java 
b/src/main/java/org/apache/maven/plugin/compiler/DiagnosticLogger.java
index bc588c7..6c1b92f 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/DiagnosticLogger.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/DiagnosticLogger.java
@@ -181,7 +181,7 @@ final class DiagnosticLogger implements 
DiagnosticListener<JavaFileObject> {
      *
      * @param cause if compilation failed with an exception, the cause
      */
-    Optional<String> firstError(Exception cause) {
+    Optional<String> firstError(Throwable cause) {
         return Optional.ofNullable(cause != null && firstError == null ? 
cause.getMessage() : firstError);
     }
 
diff --git a/src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java 
b/src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java
index d061426..c32d7bf 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java
@@ -654,6 +654,7 @@ public class ToolExecutor {
                 
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, 
Set.of(outputForRelease));
                 latestOutputDirectory = outputForRelease;
                 unit.outputForRelease = outputForRelease;
+                sourcesForDebugFile.add(unit);
                 /*
                  * Compile the source files now. The following loop should be 
executed exactly once.
                  * It may be executed twice when compiling test classes 
overwriting the `module-info`,
@@ -681,7 +682,6 @@ public class ToolExecutor {
                     if (workaroundNeedsClose) {
                         workaround.close();
                     }
-                    sourcesForDebugFile.add(unit);
                     if (!success) {
                         break compile;
                     }

Reply via email to