In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
1. Dependence of Maven
Maven's dependencies are configured through the dependencis element, which is one of the most powerful features of Maven. It supports transitive dependency.
1.1 add dependency
In Maven, you need to define one or more dependency elements in dependencies to declare one or more dependencies of the project.
Each dependent element dependency includes:
For example: add a jar package for junit tests to a project, which can be defined as follows
4.0.0 com.fz ShiroTest war 0.0.1-SNAPSHOT ShiroTest Maven Webapp http://maven.apache.org junit junit 4.11 test 1.2 dependency range (sope) the relationship between the dependency range and classpath depends on The dependent scope Scope is valid for compiling classpath, valid for testing classpath, valid for runtime classpath valid examples compileYYYspring-coretest-Y-JUnitprovidedYY-servlet-apiruntime-YYJDBC driver implementing systemYY- native Transitivity of class library files outside the Maven repository 1.3 dependencies
In Maven, a dependency is more than just a JAR. It is a POM file, and this POM may also declare dependencies on other artifacts. These dependencies are called transitive dependencies.
The so-called transitive dependency is: if project A depends on project B, and project B itself depends on project C, then project An also depends on project C.
This dependency is based on the scope of compile.
If your project needs to rely on an A library, the A library itself depends on three other libraries. When you configure a dependency on library An in dependencies, Maven automatically depends on three other libraries. You don't have to rely on yourself anymore. Just like Spring and Hibernate. When you configure it, you only need to configure Spring and Hibernate.
When Maven downloads the corresponding dependent jar, it also downloads the pom file for that jar. This file is particularly important for transitive dependencies.
This pom file is not much different from the pom.xml file we are writing now, and it is the same after opening it.
The following is the pom file (hibernate-core-4.3.10.Final.pom) of hibernate-core-4.3.10.Final.jar
4.0.0 org.hibernate hibernate-core 4.3.10.Final org.jboss.logging jboss-logging 3.1.3.GA compile org.jboss.logging jboss-logging-annotations 1.2.0.Beta1 compile org.jboss.spec.javax.transaction jboss-transaction-api_1.2_spec 1.0.0.Final compile Dom4j dom4j 1.6.1 compile Core Hibernate O/RM functionality The core O/RM functionality as provided by Hibernate http://hibernate.org Hibernate.org http://hibernate.org jira https://hibernate.atlassian.net/browse/HHH http://github.com/hibernate/hibernate-orm scm:git: http://github.com/hibernate/hibernate-orm.git scm:git:git@github.com : hibernate/hibernate-orm.git GNU Lesser General Public License http://www.gnu.org/licenses/lgpl-2.1.html See discussion at http://hibernate.org/license for more details. Repo hibernate-team The Hibernate Development Team Hibernate.org http://hibernate.org
You can see that the jar package on which hibernate-core-4.3.10.jar depends has been defined in the hibernate-core-4.3.10.Final.pom file.
1.2.1 conflicts that depend on transitivity 1. The first case
Project A depends on project B1.0 and project C on project B1.1. Project D depends on both projects An and C, so whichever is written first depends on which version.
In other words, whether it depends on log4j1.2.17 or log4j1.2.16 depends on the order in which its dependency appears.
Whichever order of dependencies comes first depends on it.
It can be seen that the above user-core is in front of user-log, while the log4j of user-core is 1.2.17. So the final log4j of user-dao is version 1.2.17.
By the same token, if you change places. User-log is in front of user-core.
Com.fz.user user-log 0.0.1-SNAPSHOT com.fz.user user-core 0.0.1-SNAPSHOT
So the result is
two。 The second case
If the length of the path is inconsistent, choose the minimum path.
Log4j path in user-dao: user-dao= > user-core= > log4j1.2.17
Log4j path in user-log: user-log= > log4j1.2.16
It can be seen that the log4j path of user-log is shorter, so this is 1.2.16.
If you replace user-log with user-core here, then the log4j path of user-core is also shorter than that of user-dao. The result must be log4j1.2.17.
What if I don't want to rely on log4j in the user-core and user-log modules?
Then try adding another dependency yourself.
You can see that Maven will give priority to relying on the dependeny defined by itself.
1.2.2 eliminate unwanted transitive dependencies through the exclusions element
The above problems can be determined by changing the appropriate order to determine the dependent version, of course, you can also use the dependency exclusion feature. To precisely control the version used.
Eliminate dependencies: remove the * * jar package from this module.
For example, the log4j version of user-log is definitely used in the following case, because it comes first. If you don't want to change the version by adjusting the order now, you can use to exclude dependencies.
Excluding dependencies is the exclusions element under the dependency element. For example, if we exclude the log4j in user-log, we can only find log4j in user-core.
You can see that although user-log is written on it, the log4j in the module will be excluded through exclusion.
1.2.3 Summary of solutions to rely on transitive conflicts
It is solved by adjusting the order of dependency: the order of dependencies depends on which one comes first.
Add a dependeny to solve the problem yourself: because the path is the smallest.
Eliminate unwanted transitive dependencies through the exclusions element
1.4 the bounds of dependent versions
When relying on a project, you don't have to specify a specific version. You can also specify a version range
(,) does not contain
[,] contains
For example: rely on a version of Junit that is greater than or equal to 3.8 but less than 4.0
Junit junit [3.8, 4.0)
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.