/** * Gets version of given dependency. * @param groupId of the dependency. * @param artifactId of the dependency. * @return Version number. */ default Optional<String> getDependencyVersion(String groupId, String artifactId) { List<Dependency> dependencies = getDependencies(true); for (Dependency dep : dependencies) { String scope = dep.getScope(); if ("test".equals(scope) || (artifactId != null && !artifactId.equals(dep.getGav().getArtifactId()))) { continue; } if (dep.getGav().getGroupId().equals(groupId)) { return Optional.of(dep.getGav().getVersion()); } } return Optional.empty(); }
private void addArtifactsWithYaml(Set<URL> artifactSet, String dependencyYaml) { final List<Dependency> artifacts = getContext().getDependencies(isIncludeTransitive()); for (Dependency artifact : artifacts) { if ("compile".equals(artifact.getScope()) && "jar".equals(artifact.getType())) { File file = artifact.getLocation(); try { URL url = new URL("jar:" + file.toURI().toURL() + "!/" + dependencyYaml); artifactSet.add(url); } catch (MalformedURLException e) { getLog().debug("Failed to create URL for %s: %s", file, e); } } } // lets look on the current plugin classpath too if (isIncludePlugin()) { Enumeration<URL> resources = null; try { resources = getClass().getClassLoader().getResources(dependencyYaml); } catch (IOException e) { getLog().error("Could not find %s on the classpath: %s", dependencyYaml, e); } if (resources != null) { while (resources.hasMoreElements()) { URL url = resources.nextElement(); artifactSet.add(url); } } } }