我想构建类似于mvn dependency:tree
. 如果依赖项有exclusions
标签,则其传递依赖项将不会显示在解析结果中。
但是,我尝试使用类似于演示示例的内容,在其中我向依赖项添加排除项,希望排除该库的所有传递依赖项,但它仍然会打印完整的树。
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());