in src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java [211:300]
protected void preparePaths(Set<File> sourceFiles) {
// assert compilePath != null;
File moduleDescriptorPath = null;
boolean hasModuleDescriptor = false;
for (File sourceFile : sourceFiles) {
if ("module-info.java".equals(sourceFile.getName())) {
moduleDescriptorPath = sourceFile;
hasModuleDescriptor = true;
break;
}
}
if (hasModuleDescriptor) {
// For now only allow named modules. Once we can create a graph with ASM we can specify exactly the modules
// and we can detect if auto modules are used. In that case, MavenProject.setFile() should not be used, so
// you cannot depend on this project and so it won't be distributed.
modulepathElements = new ArrayList<>(compilePath.size());
classpathElements = new ArrayList<>(compilePath.size());
pathElements = new LinkedHashMap<>(compilePath.size());
ResolvePathsResult<File> resolvePathsResult;
try {
Collection<File> dependencyArtifacts = getCompileClasspathElements(getProject());
ResolvePathsRequest<File> request = ResolvePathsRequest.ofFiles(dependencyArtifacts)
.setIncludeStatic(true)
.setMainModuleDescriptor(moduleDescriptorPath);
Toolchain toolchain = getToolchain();
if (toolchain instanceof DefaultJavaToolChain) {
request.setJdkHome(new File(((DefaultJavaToolChain) toolchain).getJavaHome()));
}
resolvePathsResult = locationManager.resolvePaths(request);
for (Entry<File, Exception> pathException :
resolvePathsResult.getPathExceptions().entrySet()) {
Throwable cause = pathException.getValue();
while (cause.getCause() != null) {
cause = cause.getCause();
}
String fileName = pathException.getKey().getName();
getLog().warn("Can't extract module name from " + fileName + ": " + cause.getMessage());
}
JavaModuleDescriptor moduleDescriptor = resolvePathsResult.getMainModuleDescriptor();
detectFilenameBasedAutomodules(resolvePathsResult, moduleDescriptor);
for (Map.Entry<File, JavaModuleDescriptor> entry :
resolvePathsResult.getPathElements().entrySet()) {
pathElements.put(entry.getKey().getPath(), entry.getValue());
}
if (compilerArgs == null) {
compilerArgs = new ArrayList<>();
}
for (File file : resolvePathsResult.getClasspathElements()) {
classpathElements.add(file.getPath());
if (multiReleaseOutput) {
if (getOutputDirectory().toPath().startsWith(file.getPath())) {
compilerArgs.add("--patch-module");
compilerArgs.add(String.format("%s=%s", moduleDescriptor.name(), file.getPath()));
}
}
}
for (File file : resolvePathsResult.getModulepathElements().keySet()) {
modulepathElements.add(file.getPath());
}
compilerArgs.add("--module-version");
compilerArgs.add(getProject().getVersion());
} catch (IOException e) {
getLog().warn(e.getMessage());
}
} else {
classpathElements = new ArrayList<>();
for (File element : getCompileClasspathElements(getProject())) {
classpathElements.add(element.getPath());
}
modulepathElements = Collections.emptyList();
}
}