in src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java [364:423]
private void setDependencyPaths(final StandardJavaFileManager fileManager) throws IOException {
final var unresolvedPaths = new ArrayList<Path>();
for (Map.Entry<PathType, List<Path>> entry : dependencies.entrySet()) {
List<Path> paths = entry.getValue();
PathType key = entry.getKey();
if (key instanceof JavaPathType type) {
/*
* Dependency to a JAR file (usually).
* Placed on: --class-path, --module-path.
*/
Optional<JavaFileManager.Location> location = type.location();
if (location.isPresent()) { // Cannot use `Optional.ifPresent(…)` because of checked IOException.
var value = location.get();
if (value == StandardLocation.CLASS_PATH) {
classpath = new ArrayList<>(paths); // Need a modifiable list.
paths = classpath;
if (isPartialBuild && !hasModuleDeclaration) {
/*
* From https://docs.oracle.com/en/java/javase/24/docs/specs/man/javac.html:
* "When compiling code for one or more modules, the class output directory will
* automatically be checked when searching for previously compiled classes.
* When not compiling for modules, for backwards compatibility, the directory is not
* automatically checked for previously compiled classes, and so it is recommended to
* specify the class output directory as one of the locations on the user class path,
* using the --class-path option or one of its alternate forms."
*/
paths.add(outputDirectory);
}
}
fileManager.setLocationFromPaths(value, paths);
continue;
}
} else if (key instanceof JavaPathType.Modular type) {
/*
* Source code of test classes, handled as a "dependency".
* Placed on: --patch-module-path.
*/
Optional<JavaFileManager.Location> location = type.rawType().location();
if (location.isPresent()) {
try {
fileManager.setLocationForModule(location.get(), type.moduleName(), paths);
} catch (UnsupportedOperationException e) { // Happen with `PATCH_MODULE_PATH`.
var it = Arrays.asList(type.option(paths)).iterator();
if (!fileManager.handleOption(it.next(), it) || it.hasNext()) {
throw new CompilationFailureException("Cannot handle " + type, e);
}
}
continue;
}
}
unresolvedPaths.addAll(paths);
}
if (!unresolvedPaths.isEmpty()) {
var sb = new StringBuilder("Cannot determine where to place the following artifacts:");
for (Path p : unresolvedPaths) {
sb.append(System.lineSeparator()).append(" - ").append(p);
}
logger.warn(sb);
}
}