in src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java [268:319]
private void addImplicitDependencies(List<SourceDirectory> sourceDirectories, Map<PathType, List<Path>> addTo)
throws IOException {
if (SUPPORT_LEGACY && multiReleaseOutput) {
var paths = new TreeMap<Integer, Path>();
Path root = SourceDirectory.outputDirectoryForReleases(outputDirectory);
Files.walk(root, 1).forEach((path) -> {
int version;
if (path.equals(root)) {
path = outputDirectory;
version = 0;
} else {
try {
version = Integer.parseInt(path.getFileName().toString());
} catch (NumberFormatException e) {
throw new CompilationFailureException("Invalid version number for " + path, e);
}
}
if (paths.put(version, path) != null) {
throw new CompilationFailureException("Duplicated version number for " + path);
}
});
/*
* Find the module name. If many module-info classes are found,
* the most basic one (with lowest Java release number) is taken.
*/
String moduleName = null;
for (Path path : paths.values()) {
path = path.resolve(MODULE_INFO + CLASS_FILE_SUFFIX);
if (Files.exists(path)) {
try (InputStream in = Files.newInputStream(path)) {
moduleName = ModuleDescriptor.read(in).name();
}
break;
}
}
/*
* If no module name was found in the classes compiled for previous Java releases,
* search in the source files for the Java release of the current compilation unit.
*/
if (moduleName == null) {
for (SourceDirectory dir : sourceDirectories) {
moduleName = parseModuleInfoName(dir.root.resolve(MODULE_INFO + JAVA_FILE_SUFFIX));
if (moduleName != null) {
break;
}
}
}
var pathType = (moduleName != null) ? JavaPathType.patchModule(moduleName) : JavaPathType.CLASSES;
addTo.computeIfAbsent(pathType, (key) -> new ArrayList<>())
.addAll(paths.descendingMap().values());
}
}