Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a maven equivalent of rpm --whatprovides for a jar file?

How do I use maven or another tool to find which dependency of a dependency which provides a particular jar? Sometimes they're three or four dependencies deep.

like image 876
kolobcreek Avatar asked Oct 14 '22 03:10

kolobcreek


2 Answers

If you want to find out from where a transitive dependency is coming from for a given project, then the Maven Dependency Plugin is indeed your friend. Use it with the includes parameter that allows to specify a comma-separated list of artifacts to filter the serialized dependency tree by, or null not to filter the dependency tree. The artifact syntax is defined by StrictPatternIncludesArtifactFilter.

About the syntax, the javadoc writes:

The artifact pattern syntax is of the form

[groupId]:[artifactId]:[type]:[version]

Where each pattern segment is optional and supports full and partial * wildcards. An empty pattern segment is treated as an implicit wildcard.

For example, org.apache.* would match all artifacts whose group id started with org.apache., and :::*-SNAPSHOT would match all snapshot artifacts.

Here is an example (I want to find from where the activation artifact is coming from on a project):

$ mvn dependency:tree -Dincludes=:activation::
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Java EE 6 Demo - Petstore - Domain
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] name.thivent.samples.javaee6.domain:domain:jar:1.0-SNAPSHOT
[INFO] \- org.hibernate:hibernate-validator:jar:4.0.2.GA:runtime
[INFO]    \- javax.xml.bind:jaxb-api:jar:2.1:runtime
[INFO]       \- javax.activation:activation:jar:1.1:runtime
[INFO] ------------------------------------------------------------------------
...

M2Eclipse provides a nice front-end to the dependency:tree if you are using it.

For something "closer" to rpm --whatprovides (i.e. without searching for a particular project), you would have to use a repository search engine. Here is an example for activation-1.1.jar (see the This artifact is used by ... section).

like image 90
Pascal Thivent Avatar answered Oct 18 '22 13:10

Pascal Thivent


I suppose you are looking for:

mvn dependency:tree

Edit: There are more options available to analyze dependencies. Have a look at the documentation

like image 42
Hardcoded Avatar answered Oct 18 '22 14:10

Hardcoded