Tharik Kanaka
Tharik Kanaka

Reputation: 2510

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.

enter image description here

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 );
    }

Upvotes: 6

Views: 10262

Answers (2)

carlspring
carlspring

Reputation: 32717

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

Upvotes: 6

Maverik
Maverik

Reputation: 47

If you are using eclipse with maven2 plugin, then when you open pom file, it displays a couple of views to see dependencies as per your requirement.

Upvotes: 0

Related Questions