in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java [1433:1480]
final DependencyResolverResult resolveDependencies(boolean hasModuleDeclaration) throws IOException {
DependencyResolver resolver = session.getService(DependencyResolver.class);
if (resolver == null) { // Null value happen during tests, depending on the mock used.
return null;
}
var allowedTypes = EnumSet.of(JavaPathType.CLASSES, JavaPathType.PROCESSOR_CLASSES);
if (hasModuleDeclaration) {
allowedTypes.add(JavaPathType.MODULES);
allowedTypes.add(JavaPathType.PROCESSOR_MODULES);
}
DependencyResolverResult dependencies = resolver.resolve(DependencyResolverRequest.builder()
.session(session)
.project(project)
.requestType(DependencyResolverRequest.RequestType.RESOLVE)
.pathScope(compileScope)
.pathTypeFilter(allowedTypes)
.build());
/*
* Report errors or warnings. If possible, we rethrow the first exception directly without
* wrapping in a `MojoException` for making the stack-trace a little bit easier to analyze.
*/
Exception exception = null;
for (Exception cause : dependencies.getExceptions()) {
if (exception != null) {
exception.addSuppressed(cause);
} else if (cause instanceof UncheckedIOException e) {
exception = e.getCause();
} else if (cause instanceof RuntimeException || cause instanceof IOException) {
exception = cause;
} else {
exception = new CompilationFailureException("Cannot collect the compile-time dependencies.", cause);
}
}
if (exception != null) {
if (exception instanceof IOException e) {
throw e;
} else {
throw (RuntimeException) exception; // A ClassCastException here would be a bug in above loop.
}
}
if (ProjectScope.MAIN.equals(compileScope.projectScope())) {
String warning = dependencies.warningForFilenameBasedAutomodules().orElse(null);
if (warning != null) { // Do not use Optional.ifPresent(…) for avoiding confusing source class name.
logger.warn(warning);
}
}
return dependencies;
}