maven dependency and dependency conflicts delivery

Reference: HTTPS: //blog.csdn.net/honghailiang888/article/details/53019635, https://www.cnblogs.com/LaiCuiTing/p/9542525.html

A, Maven Introduction

Maven is a cross-platform project management tool. With a remarkably successful organization of the Apache open source project, which mainly serve the project based on the Java platform to create, dependency management, and project information management.

 

Under the root element of dependencies project dependency may comprise one or more elements, one or more items to declare dependency. Each dependent can contain elements include:
basic coordinate dependent, for any one dependent, the basic coordinates is the most important, Maven needs to find the dependence of the coordinates to: groupId, artifactId and version.
type: dependent type, defined by the coordinates corresponding to the item packaging. In most cases, the elements do not have to declare a default of jar.
scope: the scope of the dependent, the following will be explain.
optional: dependent on whether the mark is optional.
exclusions: transitive dependency to exclude
most of the basic coordinate dependency declarations include only

 

2, depending on the range of

Maven main code at compile time need to use a classpath, when compiling and executing tests will use another set of classpath, when the actual operation of the project, will use a classpath.

Dependence range is used to control the relationship between the dependent and the three classpath (compilation classpath, test classpath, run classpath) is, Maven has the following range-dependent:
the compile: compile dependent range. If not specified, the default will depend on the scope. Use this dependence range Maven dependency to compile, test, Operation of Three classpath are valid. A typical example is the spring-core, need to use the dependency in the time to compile, test, and run.
provided: provided dependent range. Use this dependence range Maven dependency effective for compiling and testing classpath, but not in operation. A typical example is the servlet-api, compile and test items that rely when needed, but when the program is running, since the vessel has been provided, there is no need to repeatedly Maven introduced again.
test: testing relies range. Use this dependence range Maven dependency is valid only for the test classpath, you will not be able to use such reliance in the use of compiled code or run the main project. A typical example is the JUnit, it is only required to compile and test code when running tests.
range dependent runtime: runtime. Use of this range dependent Maven dependence CLASSPATH effective testing and operation, but not in the main code when compiling. A typical example is the JDBC driver implementation, compile the project main code only requires JDK JDBC interface provided, when only performing a test or run programs only need to achieve the above-mentioned specific interface JDBC driver.
system: system relies range. This relies rely scope consistent with the provided range represented, for compiling and testing CLASSPATH effective, but not in operation. Except that the file must be specified by the dependent element systemPath explicitly range dependent path system. Because such reliance is not resolved by Maven repository, and often bind with the native system, may result in the construction of non-portable, and therefore should be used with caution, systemPath elements can reference environment variables.

3, transitive dependencies

Transitive dependencies is a new feature added in maven2, the role of this feature is that you need to consider your dependent libraries needed to rely on libraries, will be able to rely on automatic dependent module is introduced. For example, we rely on the spring of the library, but the spring itself has a dependency, if no transitive dependencies then we need to understand the project dependencies spring, add yourself to our project. With transitive dependencies mechanism, when using the Spring Framework will not have to consider what it depends on, do not worry about the introduction of unnecessary dependencies. Maven parses each depend directly POM, indirectly dependent those necessary to form transitive dependencies introduced into the current project.

Suppose A is dependent on B, B relies for C, we say that A is the first to directly dependent B, B to C is directly dependent on the second, A to C is a transitive dependency. Range of the first and second direct depend directly dependent range determines the range of the transmission-dependent.

The leftmost row represents a first range of direct dependency, the top row represents a second range of direct dependency, the intermediate cross-cell range, said transmitting dependence.

compile test provided runtime
compile compile --- --- runtime
test test --- --- test
provided provided --- provided provided
runtime runtime --- --- runtime

4. Dependencies Principle

1) Shortest Path First: Who is nearest to use who rely on the jar package

A is a C reaches C-> B-> A

C B is the arrival C-> B

E.g:

A version of the commons-io 2.4

Version B of commons-io 2.0

C dependent on B, B depends on A

Junit package of the C version 2.0

 

2) If the two paths are the same length of time?

2.1) in different pom:

A is C reaches C-> A

C B is the arrival C-> B

See the pom file dependencies two who works in front of which version is to use

2.2) with a pom in:

The latter overwrite the previous


Reliance conflict:

Reference: https://segmentfault.com/a/1190000014938685?utm_source=tag-newest

Guess you like

Origin www.cnblogs.com/fxtx/p/11578837.html