Turn "maven Combat (vii)---delivery dependencies

Source: Internet
Author: User

Original blog from: http://blog.csdn.net/liutengteng130/article/details/47000069 thanks!

Suppose a-->c b-->a ==> b-->c ,a relies on C is directly dependent,B depends on a is directly dependent on ,B relies on C as a transitive dependency.

Phenomenon One

For example:a-->log1.0 b-->log2.0 c-->a,b Then we look at dependencies:

User-core relies on log4j 1.2.17

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

the User-log package relies on log4j 1.2.9

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
</dependency>

User-service relies on User-core and also relies on user-log

You can see that the version number of the log4j that User-service relies on is 1.2.9. Because relying on the log first, after relying on the Core,user-service dependency log4j is equivalent to indirect dependency. Therefore, when there is an indirect dependency, which one depends on, it depends on which package is indirectly dependent.

Summary: Indirect dependency, if the level is the same, depends on the first reference dependency.

Phenomenon II

Rely on User-core first, then rely on user-log. Here 's a look at the Commons-logging.jar version number:

User-core inside the commons-logging version number is 1.0.4

User-log inside the commons-logging version number is 1.1.1

User-service inside The commons-logging version number is 1.1.1

According to the first,User-service inside the jar version should be 1.0.4, now why is 1.1.1 ?

Let us analyze:

User-core is dependent on dbunit, and Commons-logging.jar is referenced as a dependency.

User-log inside is directly quoted Commons-logging.jar

So they are on different dependency trees, and the shallower the depth is the preferred choice.

Summary

1. On the project's dependency tree, the shallower the depth, the more limited the choice.

2. If two dependent packages are on the same level as the dependent tree, who is selected before.

in summary, avoid the best practices that cause version problems to occur when passing dependencies. In general, if the project relies directly on multiple modules of a framework, it is best to declare these dependencies all.

Turn "maven Combat (vii)---delivery dependencies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.