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.
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 withorg.apache., and:::*-SNAPSHOTwould 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).
I suppose you are looking for:
mvn dependency:tree
Edit: There are more options available to analyze dependencies. Have a look at the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With