Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find maven dependencies of any given project?

Tags:

java

maven

aether

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 );
    }
like image 670
Tharik Kanaka Avatar asked Sep 28 '22 21:09

Tharik Kanaka


1 Answers

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
like image 102
carlspring Avatar answered Oct 11 '22 15:10

carlspring