I want to build something similar to mvn dependency:tree
. If a dependency has an exclusions
tag, then its transitive dependencies will not be shown in the resolved result.
However, I try to have something similar to the demo example, where I add an exclusion to a dependency, hoping to exclude all its transitive dependencies of this library, but it still prints the full tree.
RepositorySystem system = Booter.newRepositorySystem(Booter.selectFactory(args));
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact artifact1 = new DefaultArtifact("com.google.oauth-client:google-oauth-client:1.31.5");
Exclusion exclusion = new Exclusion("*", "*", null, null);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRepositories(Booter.newRepositories(system, session));
collectRequest.setDependencies(List.of(new Dependency(artifact1, "", false, Set.of(exclusion))));
CollectResult collectResult = system.collectDependencies(session, collectRequest);
collectResult.getRoot().accept(new ConsoleDependencyGraphDumper());