Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display omitted versions in maven dependency:tree?

In Eclipse, when I go to the Maven Dependency Hierarchy page, I get output that states what conflicts caused versions to be omitted:

eclipse maven version

However, if I use dependency:tree, that's omitted and I only see the evrsions which are actually used:

|  +- commons-httpclient:commons-httpclient:jar:3.1:compile
|  +- commons-codec:commons-codec:jar:1.4:compile
|  +- commons-io:commons-io:jar:2.4:compile
|  +- commons-net:commons-net:jar:3.1:compile
|  +- javax.servlet:servlet-api:jar:2.5:compile

And later on the actually referenced versions...

+- commons-collections:commons-collections:jar:3.1:compile

Is there any way to get dependency:tree to output the versions omitted for conflict?

Thanks!

like image 675
Robert Fraser Avatar asked Feb 23 '16 21:02

Robert Fraser


People also ask

How do you analyze a dependency tree in Maven?

A project's dependency tree can be filtered to locate specific dependencies. For example, to find out why Velocity is being used by the Maven Dependency Plugin, we can execute the following in the project's directory: mvn dependency:tree -Dincludes=velocity:velocity.

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.

How do I get Maven dependency tree?

How to get the Maven Dependency Tree of a Project. We can run mvn dependency:tree command in the terminal to print the project dependency tree. For our example, I will be using the Mockito Tutorial project. You can download the project from the GitHub repository.


3 Answers

Yes, you can have the omitted artifacts by setting the verbose attribute to true:

Whether to include omitted nodes in the serialized dependency tree.

This attribute defaults to false. On the command line, you would have

mvn dependency:tree -Dverbose=true
like image 63
Tunaki Avatar answered Oct 19 '22 19:10

Tunaki


According to this, the -Dverbose=true argument is ignored in versions 3.0 of the plugin and above. You need to use an older version; the above link suggests the following (works for me):

mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:tree -Dverbose=true
like image 3
Nat Ritmeyer Avatar answered Oct 19 '22 19:10

Nat Ritmeyer


I suggest to use the depgraph-maven-plugin.

  • to see all dependencies, set showDuplicates to true
    • this will include dependencies that dependency:tree would show with verbose option
  • to see conflicts, set showConflicts to true
  • has various filters to include/exclude projects
  • can export to various formats, including dot file that can be rendered with GraphViz
    • I use vscode plugin GraphViz Interactive Preview to render and view dot files.

Example config:

<plugin>
    <groupId>com.github.ferstl</groupId>
    <artifactId>depgraph-maven-plugin</artifactId>
    <version>3.3.0</version>
    <configuration>
        <showDuplicates>true</showDuplicates>
        <showConflicts>true</showConflicts>
        <includes>
            <!-- groupId:artifactId:type:classifier -->
            <include>com.mycompany*:*</include>
        </includes>
    </configuration>
</plugin>

Then run mvn depgraph:graph in your project to find a new file in target/dependency-graph.dot.

Note that you can include the plugin with scope provided such that it will not be included in any build artifact.

like image 3
mihca Avatar answered Oct 19 '22 18:10

mihca