File (@Nullable String overrideMavenHome) { if (!isEmptyOrSpaces(overrideMavenHome)) { return MavenUtil.getMavenHomeFile(staticOrBundled(resolveMavenHomeType(overrideMavenHome))); } String m2home = System.getenv(ENV_M2_HOME); if (!isEmptyOrSpaces(m2home)) { final File homeFromEnv = new File(m2home); if (isValidMavenHome(homeFromEnv)) { return homeFromEnv; } } String mavenHome = System.getenv("MAVEN_HOME"); if (!isEmptyOrSpaces(mavenHome)) { final File mavenHomeFile = new File(mavenHome); if (isValidMavenHome(mavenHomeFile)) { return mavenHomeFile; } } String userHome = SystemProperties.getUserHome(); if (!isEmptyOrSpaces(userHome)) { final File underUserHome = new File(userHome, M2_DIR); if (isValidMavenHome(underUserHome)) { return underUserHome; } } if (SystemInfo.isMac) { File home = fromBrew(); if (home != null) { return home; } if ((home = fromMacSystemJavaTools()) != null) { return home; } } else if (SystemInfo.isLinux) { File home = new File("/usr/share/maven"); if (isValidMavenHome(home)) { return home; } home = new File("/usr/share/maven2"); if (isValidMavenHome(home)) { return home; } } return MavenDistributionsCache.resolveEmbeddedMavenHome().getMavenHome().toFile(); }