Maven where is dependency coming from




















Although transitive dependencies can implicitly include desired dependencies, it is a good practice to explicitly specify the dependencies your source code uses directly.

This best practice proves its value especially when the dependencies of your project change their dependencies. For example, assume that your project A specifies a dependency on another project B, and project B specifies a dependency on project C. Another reason to directly specify dependencies is that it provides better documentation for your project: one can learn more information by just reading the POM file in your project, or by executing mvn dependency:tree.

Maven also provides dependency:analyze plugin goal for analyzing the dependencies: it helps making this best practice more achievable. Dependency scope is used to limit the transitivity of a dependency and to determine when a dependency is included in a classpath. Each of the scopes except for import affects transitive dependencies in different ways, as is demonstrated in the table below.

If a dependency is set to the scope in the left column, a transitive dependency of that dependency with the scope across the top row results in a dependency in the main project with the scope listed at the intersection.

If no scope is listed, it means the dependency is omitted. However, if a library you depend on extends a class from another library, both must be available at compile time. For this reason, compile time dependencies remain as compile scope even when they are transitive. The dependency management section is a mechanism for centralizing dependency information.

When you have a set of projects that inherit from a common parent, it's possible to put all information about the dependency in the common POM and have simpler references to the artifacts in the child POMs. The mechanism is best illustrated through some examples.

Given these two POMs which extend the same parent:. These two example POMs share a common dependency and each has one non-trivial dependency. This information can be put in the parent POM like this:. In many cases, these dependencies will refer to jar artifacts with no classifier. A second, and very important use of the dependency management section is to control the versions of artifacts used in transitive dependencies. An empty pattern segment is treated as an implicit wildcard.

For example, org. The dependency tree can also be filtered to remove specific dependencies. For example, to exclude Plexus dependencies from the tree, we can execute the following:.

Multiple patterns can be specified when filtering the dependency tree by separating the patterns with commas. Learn more. In Maven 2, how do I know from which dependency comes a transitive dependency? Ask Question. Asked 13 years, 2 months ago. Active 1 year, 10 months ago.

Viewed 50k times. Improve this question. Rich Seller Add a comment. Active Oldest Votes. Improve this answer. Rex A. Rex 31k 21 21 gold badges 86 86 silver badges 95 95 bronze badges. This didn't work for me; all I got was errors about unsupported 'legacy' values. Running David Crow's version i. Using the Maven Dependency Plugin : mvn dependency:tree. David Crow David Crow Koray Tugay



0コメント

  • 1000 / 1000