ArtifactResolver { public CollectionResult collectTransitiveDeps(String... gavs) throws RepositoryException { Set<Artifact> artifacts = new HashSet<>(); Set<Exception> failures = new HashSet<>(); for (String gav : gavs) { LOG.debug("Artifact resolution for {}", gav); collectTransitiveDeps(gav, artifacts, failures); } return new CollectionResult(failures, artifacts); } ArtifactResolver(RepositorySystem repositorySystem, RepositorySystemSession session,
            List<RemoteRepository> repositories); static DependencySelector getRevapiDependencySelector(boolean resolveProvidedDependencies, boolean resolveTransitiveProvidedDependencies); static DependencyTraverser getRevapiDependencyTraverser(boolean resolveProvidedDependencies, boolean resolveTransitiveProvidedDependencies); Artifact resolveArtifact(String gav); Artifact resolveNewestMatching(String gav, @Nullable String upToVersion, Pattern versionMatcher,
                                          boolean remoteOnly, boolean upToInclusive); CollectionResult collectTransitiveDeps(String... gavs);  }
@Test public void testResolvesCompileScopes() throws RepositoryException { ArtifactResolver resolver = getResolver(false, false); CollectionResult res = resolver.collectTransitiveDeps("used-scopes:root:0"); assertTrue(res.getFailures().isEmpty()); Set<Artifact> artifacts = res.getResolvedArtifacts(); assertEquals(2, artifacts.size()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-compile-compile"::equals).count()); }
@Test public void testResolvesCompileAndTopLevelProvidedScopes() throws RepositoryException { ArtifactResolver resolver = getResolver(true, false); CollectionResult res = resolver.collectTransitiveDeps("used-scopes:root:0"); assertTrue(res.getFailures().isEmpty()); Set<Artifact> artifacts = res.getResolvedArtifacts(); assertEquals(4, artifacts.size()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-compile-compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("provided"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-provided-compile"::equals).count()); }
@Test public void testResolvesCompileAndTransitiveProvidedScopes() throws RepositoryException { ArtifactResolver resolver = getResolver(true, true); CollectionResult res = resolver.collectTransitiveDeps("used-scopes:root:0"); assertTrue(res.getFailures().isEmpty()); Set<Artifact> artifacts = res.getResolvedArtifacts(); assertEquals(6, artifacts.size()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-compile-compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-compile-provided"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("provided"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-provided-compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-provided-provided"::equals).count()); }
@Test public void testHonorsExclusions() throws RepositoryException { ArtifactResolver resolver = getResolver(false, false); CollectionResult res = resolver.collectTransitiveDeps("exclusions:root:0"); assertTrue(res.getFailures().isEmpty()); Set<Artifact> artifacts = res.getResolvedArtifacts(); assertEquals(3, artifacts.size()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("dep"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("included"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("included-included"::equals).count()); }
@Test public void testIgnoresNonCompileAndProvidedScopes() throws RepositoryException { ArtifactResolver resolver = getResolver(false, false); CollectionResult res = resolver.collectTransitiveDeps("ignored-scopes:root:0"); assertTrue(res.getFailures().isEmpty()); Set<Artifact> artifacts = res.getResolvedArtifacts(); assertEquals(2, artifacts.size()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("included"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("optional"::equals).count()); }