MavenVersion { public static String version(@NonNull Class<?> aClass, @NonNull String groupId, @NonNull String artifactId) { String pomProperties = String.format("META-INF/maven/%s/%s/pom.properties", groupId, artifactId); return Optional .of(pomProperties) .map(aClass.getClassLoader()::getResource) .map(MavenVersion::loadProperties) .map(p -> p.getProperty("version")) .orElseGet(() -> { log.warn("Unable to read {}", pomProperties); return "unknown"; }); }  static String version(@NonNull Class<?> aClass, @NonNull String groupId, @NonNull String artifactId);  }
@Test public void test() throws Exception { assertThat(MavenVersion.version(Logger.class, "org.slf4j", "slf4j-api").toString(), is("1.7.25")); }