in src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java [1161:1210]
public JavaCompiler compiler() throws MojoException {
/*
* Use the `compilerId` as identifier for toolchains.
* I.e, we assume that `compilerId` is also the name of the executable binary.
*/
getToolchain().ifPresent((tc) -> {
logger.info("Toolchain in maven-compiler-plugin is \"" + tc + "\".");
if (executable != null) {
logger.warn(
"Toolchains are ignored because the 'executable' parameter is set to \"" + executable + "\".");
} else {
fork = true;
if (compilerId == null) {
compilerId = DEFAULT_EXECUTABLE;
}
// TODO somehow shaky dependency between compilerId and tool executable.
executable = tc.findTool(compilerId);
}
});
if (fork) {
if (executable == null) {
executable = DEFAULT_EXECUTABLE;
}
return new ForkedCompiler(this);
}
/*
* Search a `javax.tools.JavaCompiler` having a name matching the specified `compilerId`.
* This is done before other code that can cause the mojo to return before the lookup is
* done, possibly resulting in misconfigured POMs still building. If no `compilerId` was
* specified, then the Java compiler bundled with the JDK is used (it may be absent).
*/
if (logger.isDebugEnabled()) {
logger.debug(
"Using " + (compilerId != null ? ("compiler \"" + compilerId + '"') : "system compiler") + '.');
}
if (compilerId == null) {
compilerId = DEFAULT_EXECUTABLE;
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler != null) {
return compiler;
}
} else {
for (JavaCompiler t : ServiceLoader.load(JavaCompiler.class)) {
if (compilerId.equals(t.name())) {
return t;
}
}
}
throw new CompilationFailureException("No such \"" + compilerId + "\" compiler.");
}