Is there a maven command using which I could find out list of all bundles who directly or transitively depend on a given bundle?
mvn dependency:tree
should give you that
Related
Impact of exclusion in the context of jar packaging(simple/fat jar using shade plugin). What i mean here, how can it be verified by extracting the jar.
When a dependency is excluded, it is removed from the dependency tree at that point. You can check this with mvn dependency:tree. It might still come in through other ways (e.g. as transitive dependency of some other dependency). You can check that with mvn dependency:list.
I have a simple pom.xml which have only JUnit dependency and exec-maven-plugin.
But when I say "mvn install" I see lot of dependencies downloading.
Are this mandatory dependencies by maven?
I am listing a few here :
ClassWorlds
Commons-logging-api
log4j
backport-util-concurrent
Are this mandatory dependencies by maven
Yes, those are transitive dependencies.
This allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically
See "Resolving conflicts using the dependency tree"
A project's dependency tree can be expanded to display dependency conflicts. For example, to find out why Commons Collections 2.0 is being used by the Maven Dependency Plugin, we can execute the following in the project's directory:
mvn dependency:tree -Dverbose -Dincludes=commons-collections
In gradle, the command gradle dependencyInsight --dependency <artifact-name> prints a reverse dependency graph for a specific artifact.
Is there something equivalent in Maven?
I'm aware of mvn dependency:tree. This is the equivalent of gradle dependencies. However this is not what I'm asking about.
One way is to use filtering with maven dependency plugin
mvn dependency:tree -Dincludes=[groupId]:[artifactId]:[type]:[version]
Check the link, there is an example. The output isn't actually in reverse but it shouldn't be too hard to read it in reverse by yourself.
Eclipse-IDE has some nice features which allows dependencies to tracked without using command line. Open pom.xml, open dependency hierarchy tab and there, dependencies can be filtered. Other IDEs might have similar features as well.
Apache Velocity needs commons-collections-3.2.1.
In my pom file I have added a velocity dependency. Everything works, but when I look in the overall pom file:
$ mvn help:effective-pom
I do not see an commons-collections entry.
I had expected it should be there. Or not?
No, not if you don't specify it directly. effective-pom shows the pomfile factored in with the eventually inherited definitions from the parent pom (ie. dependencyManagement, pluginManagement, properties and so on) and the profile.
To see the full list of dependencies, including transitive dependencies, you need maven-dependency-plugin, and
mvn dependency:tree
The effective-pom does not show you all the transitive dependencies, only the POM as it will be, given whatever parents, profiles etc. you have.
You may want to try mvn dependency:tree, which will show you the projects' direct and transitive dependencies as a tree, and notice that commons-collections will be somewhere under Velocity.
Cheers,
I'd like to mvn install:install-file artifact A excluding artifact X.
A does not depend directly on X, yet down the dependency tree there are several dependencies for X.
What would be the command to perform this?
If you just run install:install-file on a jar file without -DpomFile=something, it will create a pom with no dependencies, so there's nothing to exclude. The 'X' dependency won't be represented at all.
If you pass in a pom file via -DpomFile=POMFILE, then you have the dependency structure in there, and it can include whatever exclusions you need. If you put in a dependency on X, and it in turn depends on Y, you can add an exclusion to the X dependency.
A comment from the OP suggests that this has nothing to do with install:install-file.
There is some artifact 'A' with a rich and complex dependency tree, which transitively reaches some artifact 'B' at many points. How do cope with B not being available if, in fact, it's not actually needed in the classpath?
The only solution here is to add exclusions to the POMs that reference A. Instead of trying to change the pom of A to exclude B, you have to add the exclusion of B in your own poms as part of the dependency on A. There's no other way.