title: How to exclude dependencies in aether collectDependencies
body: <p>I want to build something similar to <code>mvn dependency:tree</code>. If a dependency has an <code>exclusions</code> tag, then its transitive dependencies will not be shown in the resolved result.</p>
  <p>However, I try to have something similar to the <a href="https://github.com/apache/maven-resolver/blob/master/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/GetDependencyTree.java" rel="nofollow noreferrer">demo example</a>, 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.</p>
  <pre><code>RepositorySystem system = Booter.newRepositorySystem(Booter.selectFactory(args));
  
  RepositorySystemSession session = Booter.newRepositorySystemSession(system);
  Artifact artifact1 = new DefaultArtifact(&quot;com.google.oauth-client:google-oauth-client:1.31.5&quot;);
  Exclusion exclusion = new Exclusion(&quot;*&quot;, &quot;*&quot;, null, null);
  CollectRequest collectRequest = new CollectRequest();
  collectRequest.setRepositories(Booter.newRepositories(system, session));
  collectRequest.setDependencies(List.of(new Dependency(artifact1, &quot;&quot;, false, Set.of(exclusion))));
  CollectResult collectResult = system.collectDependencies(session, collectRequest);
  
  collectResult.getRoot().accept(new ConsoleDependencyGraphDumper());
  </code></pre>