简体   繁体   中英

How to find maven dependencies of any given project?

I am trying to building a separate project which can find maven dependencies of any given project. I was referring Aether samples but i could not find a way to define another project to find dependencies.

As shown in the following figure 1 , Project 1 has dependencies of project 2 and project 2 has dependencies of project 3. If i select project 1 on dependency finder it should show all the dependencies of project 1 which are project 2.

在此处输入图片说明

I was referring following Aether code piece but i could not figure out a way to set another project (by setting pom file or project directory)

    RepositorySystem system = Booter.newRepositorySystem();

    RepositorySystemSession session = Booter.newRepositorySystemSession( system );

    Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" );

    ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
    descriptorRequest.setArtifact( artifact );
    descriptorRequest.setRepositories( Booter.newRepositories( system, session ) );

    ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest );

    for ( Dependency dependency : descriptorResult.getDependencies() )
    {
        System.out.println( dependency );
    }

You don't need to do it programatically. You could simply invoke dependency:tree :

mvn dependency:tree

I would also recommend you invoke it with -Dverbose in case you're really, really having a hard time figuring why a certain version of a dependency is being chosen over another one (which you may be expecting it to be using instead).

Or, alternatively, if you'd like to see the dependencies in a flat form, you could also use dependency:list

mvn dependency:list

如果您使用带有 maven2 插件的 eclipse,那么当您打开 pom 文件时,它会显示几个视图以根据您的要求查看依赖项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM