static String getMavenVersion()

in src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java [108:134]


    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 version = StringUtils.trim(properties.getProperty("version"));
                    if (version != null) {
                        return version;
                    }
                }
            } catch (FileNotFoundException | MalformedURLException e) {
                // ignore
            }
        }
        return null;
    }