In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In view of the dependency characteristics of maven and what is conflict resolution, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Several features that 1.maven depends on
1.1 dependency range-scope tag
Maven has three sets of classpath during the construction process. We will rely on different classpath according to the scope of the configuration dependency, as shown below:
Compile: the default is compile, which is valid for compiling and running tests
Provided: it is valid for compiling and testing classpath, and does not need to be added at runtime. For example, jsp depends on searvlet api. For example, we are valid at compile and test time, but the container already provides servletapi at run time. If you join, it will cause conflicts.
Runtime: valid only at test and run time. The typical example, jdbc api, is enabled only when code tests are started or run
Test: it is only valid when testing. A typical example is junit, which is enabled only when testing again.
1.2 dependency transfer
For example, if we introduce a dependency spring-test, the dependency transfer feature will easily help us to get down its related dependencies, without having to worry about the problems of introducing jar, but there are also drawbacks, there are some unnecessary dependencies, which may cause conflicts.
1.3 dependency exclusion-exclusion tag
The feature of dependency exclusion is also a way to resolve dependency conflicts, which is convenient to remove unnecessary dependencies in the process of dependency transfer. This tag will be used in the dependency conflict below.
1.4 causes of dependency conflicts
After using maven for a long time, you will find the problem of dependency conflict, because the transfer feature of dependency will introduce many implicit dependencies that conflict with the existing display jar version, resulting in the problem of version conflict. To solve this problem, first look at pom.xml 's explicit and implicit dependency packages, and then use this package tree to find out the dependent packages we don't want, and manually exclude them.
two。 Rely on the resolution of conflicts
2.1 two basic principles:
1)。 Short circuit priority principle
A-> B-> logback-1.0.jar
A-> logback-1.1.jar
2)。 Declare the principle of priority first (parse first and quote first)
Related to the order in which reference coordinates are configured in project A pom, if you rely on B before C, then B takes precedence, and vice versa.
A-> B-> logback-1.0.jar
A-> C-> logback-1.1.jar
2.2 demonstrate two principles
1)。 Create three maven projects
Maven-01,maven-02,maven-03
2)。 Three engineering dependent structures:
Maven-01 relies on spring-test,maven-02,maven-03 (maven-02/03 needs to be submitted to the local repository before maven-01 can find it. Please refer to the component search process: 1.3Warehouse component search process)
Maven-02 depends on commons-logging-1.1.1
Maven-03 project depends on commons-logging-1.1.3
3)。 Take a look at myEclipse or execute mvn dependency:tree to view the dependency tree:
Myeclispe: dependency tree
4)。 Conflict resolution:
4.1 pom configuration 1:
Xml code
1. 2. Org.springframework 3. Spring-test 4. 4.2.2.RELEASE 5. 13. 15. 16. 17. Com.sohu.train 18. Maven-02 19. 1.0-SNAPSHORT 20.
Short circuit priority principle:
Maven-01- > spring-test- > spring-core- > commons-loggings-1.2 (dependency depth 3)
Maven-01- > maven-02- > commons-loggings-1.1.1 (dependency depth 2)
So the commons-loggings-1.1.1 that the maven01 project depends on
4.2 pom configuration 2:
Xml code
1. 2. Org.springframework 3. Spring-test 4. 4.2.2.RELEASE 5. 6. 7. 8. Commons-logging 9. Commons-logging 10. 11. 12. 14. 15. 16. Com.sohu.train 17. Maven-03 18. 0.0.1-SNAPSHOT 19. 21. twenty-two。 23. Com.sohu.train 24. Maven-02 25. 1.0-SNAPSHORT 26.
To quote the principle of first priority:
Maven-01- > spring-test- > spring-core
Maven-01- > maven-02- > commons-logging-1.1.1
Maven-01- > maven-03- > commons-logging-1.1.3
If pom depends on maven-02 first, it depends on commons-logging-1.1.1; on the contrary, if pom depends on maven-03 first, it depends on commons-loen.
This is the answer to the question about the dependency characteristics of maven and conflict resolution. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.