in src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java [106:133]
static String getMavenVersion(File mavenHome) throws IOException {
File mavenLib = new File(mavenHome, "lib");
File[] jarFiles = mavenLib.listFiles((dir, name) -> name.endsWith(".jar"));
if (jarFiles == null) {
throw new IllegalArgumentException("Invalid Maven home installation directory: " + mavenHome);
}
for (File file : jarFiles) {
try {
URL url = new URL("jar:" + file.toURI().toURL().toExternalForm()
+ "!/META-INF/maven/org.apache.maven/maven-core/pom.properties");
try (InputStream in = url.openStream()) {
Properties properties = new Properties();
properties.load(in);
String str = properties.getProperty("version");
String version = str == null ? null : str.trim();
if (version != null) {
return version;
}
}
} catch (FileNotFoundException | MalformedURLException e) {
// ignore
}
}
return null;
}