Maven jar package in the conflict solution

phenomenon

Create a maven project, the introduction of spring-context package.

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

At this point look lib on the left side, we find that the introduction of a coordinate, a lot more jar package, this phenomenon is called transitive dependencies, that is, the current coordinates of the dependent jar package will come with the introduction of the version here is 5.0.8 of.

Next, we introduce a springmvc. We change a version, we introduced Version 4.2.4

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>

We can see through to the idea maven analysis diagram, mvc and context and are dependent on a sprng-core, it relies on version 5.0.8, version 4.2.4 is a dependent.

So which version is true to load it. It is version 5.0.8.

At this point is that there is a conflict jar package, then we solve this problem, there are three ways.

Disclaimer priority principle

5.0.8 At this point our pom file is first declared, 4.2.4 version of the statement, we will reverse the order.


At this point we find their common dependent jar package, have become a 4.2.4 version, this is the first principle statement.

The principle of priority nearby

For example, we do not want to reverse the order, we just want to use the 4.2.4 version of spring-core. We can introduce to come alone.

At this time again, we find that rely on spring-core has become a 4.2.4 version.

The first principle is the nearest, near priority is directly dependent, directly dependent priority than the priority of transmission dependent.

Preclude reliance

This way we can pass directly dependent negative spring-core of the spring-context.

Look dependence, this time has been changed to 4.2.4.

Use exclusions labels when not write its internal version number, this is the only case do not write the version number. Because he went to the current default dependent version.

Guess you like

Origin www.cnblogs.com/jichi/p/11627487.html