Skip to content

Commit cb9fd8d

Browse files
committed
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.
1 parent 1972313 commit cb9fd8d

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,12 +1368,13 @@ private void compile(final JavaCompiler compiler, final Options configuration) t
13681368
if (!executor.applyIncrementalBuild(this, configuration)) {
13691369
return;
13701370
}
1371-
Exception failureCause = null;
1371+
Throwable failureCause = null;
13721372
final var compilerOutput = new StringWriter();
13731373
boolean success;
13741374
try {
13751375
success = executor.compile(compiler, configuration, compilerOutput);
1376-
} catch (Exception e) {
1376+
} catch (Exception | NoClassDefFoundError e) {
1377+
// `NoClassDefFoundError` may happen if a dependency of an annotation processor is missing.
13771378
success = false;
13781379
failureCause = e;
13791380
}

src/main/java/org/apache/maven/plugin/compiler/DiagnosticLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
181181
*
182182
* @param cause if compilation failed with an exception, the cause
183183
*/
184-
Optional<String> firstError(Exception cause) {
184+
Optional<String> firstError(Throwable cause) {
185185
return Optional.ofNullable(cause != null && firstError == null ? cause.getMessage() : firstError);
186186
}
187187

src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ public boolean compile(final JavaCompiler compiler, final Options configuration,
654654
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(outputForRelease));
655655
latestOutputDirectory = outputForRelease;
656656
unit.outputForRelease = outputForRelease;
657+
sourcesForDebugFile.add(unit);
657658
/*
658659
* Compile the source files now. The following loop should be executed exactly once.
659660
* It may be executed twice when compiling test classes overwriting the `module-info`,
@@ -681,7 +682,6 @@ public boolean compile(final JavaCompiler compiler, final Options configuration,
681682
if (workaroundNeedsClose) {
682683
workaround.close();
683684
}
684-
sourcesForDebugFile.add(unit);
685685
if (!success) {
686686
break compile;
687687
}

0 commit comments

Comments
 (0)