in src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java [505:536]
protected void setupMavenExecutable(InvocationRequest request) throws CommandLineConfigurationException {
if (request.getMavenExecutable() != null) {
mavenExecutable = request.getMavenExecutable();
}
if (mavenExecutable == null || !mavenExecutable.isAbsolute()) {
String executable;
if (mavenExecutable != null) {
executable = mavenExecutable.getPath();
} else {
executable = "mvn";
}
// firs look in project directory
mavenExecutable = detectMavenExecutablePerOs(baseDirectory, executable);
if (mavenExecutable == null) {
// next maven home
mavenExecutable = detectMavenExecutablePerOs(mavenHome, "/bin/" + executable);
}
if (mavenExecutable != null) {
try {
mavenExecutable = mavenExecutable.getCanonicalFile();
} catch (IOException e) {
logger.debug("Failed to canonicalize maven executable: '" + mavenExecutable + "'. Using as-is.", e);
}
} else {
throw new CommandLineConfigurationException("Maven executable: '" + executable + "'"
+ " not found at project dir: '" + baseDirectory + "' nor maven home: '" + mavenHome + "'");
}
}
}