@Test @DisplayName("Get the latest version of an existing artifact") void getLatestVersion_1() throws IOException { assertEquals("3.6.0.Beta2", getLatestVersion("org.hibernate:hibernate:")); assertEquals("3.6.0.Beta2", getLatestVersion("org.hibernate:hibernate:3.5.4-Final")); }
public static String getLatestVersion(String gav) throws IOException { checkNotNull(gav); var coordinate = ParsedCoordinate.fromCoordinate(gav); String url = MAVEN_HOST + "/maven2/" + coordinate.groupId.replaceAll("\\.", "/") + "/" + coordinate.artifactId + "/maven-metadata.xml"; try (var in = new URL(url).openStream()) { return XPathFactory.newDefaultInstance().newXPath().evaluate("/metadata/versioning/latest", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in)); } catch (XPathExpressionException | SAXException | ParserConfigurationException e) { throw new IOException(e); } }
ArtifactUtil { public static String getLatestVersion(String gav) throws IOException { checkNotNull(gav); var coordinate = ParsedCoordinate.fromCoordinate(gav); String url = MAVEN_HOST + "/maven2/" + coordinate.groupId.replaceAll("\\.", "/") + "/" + coordinate.artifactId + "/maven-metadata.xml"; try (var in = new URL(url).openStream()) { return XPathFactory.newDefaultInstance().newXPath().evaluate("/metadata/versioning/latest", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in)); } catch (XPathExpressionException | SAXException | ParserConfigurationException e) { throw new IOException(e); } } }
ArtifactUtil { public static String getLatestVersion(String gav) throws IOException { checkNotNull(gav); var coordinate = ParsedCoordinate.fromCoordinate(gav); String url = MAVEN_HOST + "/maven2/" + coordinate.groupId.replaceAll("\\.", "/") + "/" + coordinate.artifactId + "/maven-metadata.xml"; try (var in = new URL(url).openStream()) { return XPathFactory.newDefaultInstance().newXPath().evaluate("/metadata/versioning/latest", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in)); } catch (XPathExpressionException | SAXException | ParserConfigurationException e) { throw new IOException(e); } } private  ArtifactUtil(); }
ArtifactUtil { public static String getLatestVersion(String gav) throws IOException { checkNotNull(gav); var coordinate = ParsedCoordinate.fromCoordinate(gav); String url = MAVEN_HOST + "/maven2/" + coordinate.groupId.replaceAll("\\.", "/") + "/" + coordinate.artifactId + "/maven-metadata.xml"; try (var in = new URL(url).openStream()) { return XPathFactory.newDefaultInstance().newXPath().evaluate("/metadata/versioning/latest", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in)); } catch (XPathExpressionException | SAXException | ParserConfigurationException e) { throw new IOException(e); } } private  ArtifactUtil(); static Path getArtifactFile(Path directory, String coordinates); static Stream<Path> findArtifactFile(Path directory, String artifactId); static Path download(Path directory, String gav); @SuppressWarnings("deprecation") static boolean checkHash(Path directory, String gav); static String getLatestVersion(String gav); }
ArtifactUtil { public static String getLatestVersion(String gav) throws IOException { checkNotNull(gav); var coordinate = ParsedCoordinate.fromCoordinate(gav); String url = MAVEN_HOST + "/maven2/" + coordinate.groupId.replaceAll("\\.", "/") + "/" + coordinate.artifactId + "/maven-metadata.xml"; try (var in = new URL(url).openStream()) { return XPathFactory.newDefaultInstance().newXPath().evaluate("/metadata/versioning/latest", DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in)); } catch (XPathExpressionException | SAXException | ParserConfigurationException e) { throw new IOException(e); } } private  ArtifactUtil(); static Path getArtifactFile(Path directory, String coordinates); static Stream<Path> findArtifactFile(Path directory, String artifactId); static Path download(Path directory, String gav); @SuppressWarnings("deprecation") static boolean checkHash(Path directory, String gav); static String getLatestVersion(String gav);  }