002 Dependency Management

Source: Internet
Author: User

I. Overview

When we use MAVEN to build a project, there is a problem that is very troublesome, that is, dependency management, although Maven can help us to solve this problem to a certain extent, but relying on the issue between the version is still a very headache.

In Springboot, to build projects faster, we provide a dependency management feature.

Two. Resolving dependency management issues

Springboot provided us with a parent pom file, in which we developed a dependent version, which is a stable version after testing, which solves the problem of our dependent version.

We generally call this mechanism a version arbiter.

Among the springboot, for Oh we offer two ways to proceed:

[1] Introduction of a springboot parent pom complete

[2] Loading a springboot dependency manager

(1) using Springboot's parent pom file

<parent>    <groupId>org.springframework.boot</groupId>    <artifactId> spring-boot-starter-parent</artifactid>    <version>1.5.  . Release</version></parent>

We typically define this parent pom file in one of our own parent pom files, so that we can use MAVEN's aggregation capabilities.

(2) using the dependency manager

Sometimes, we already have a parent pom file, and the above method cannot be used. To do this, Springboot provides us with a dependency manager to help us use Springboot.

<dependencyManagement>     <dependencies>        <dependency> from             Spring Boot--            <groupId>org.springframework.boot</groupId>            <artifactid>spring-boot-dependencies </artifactId>            <version>1.5.  . release</version>            <type>pom</type>            <scope>import</scope>        </ Dependency>    </dependencies></dependencyManagement>

Three. Overwrite dependent version information

Sometimes, we do not want to use the version information provided by Springboot, such as the use of thymeleaf, we need to overwrite the above dependent version information.

This time, we covered the information of thymeleaf.

[1] Version information for the Pom that overrides the parent

We know that in Springboot's parent Pom information, the version information is placed in the attribute, as follows:

<properties> <!--Dependency versions--<activemq.version>5.14.5</activemq.version> <antlr2.version>2.7.7</antlr2.version> <appengine-sdk.version>1.9. -</appengine-sdk.version> <artemis.version>1.5.5</artemis.version> <aspectj.version>1.8. -</aspectj.version> <assertj.version>2.6.0</assertj.version> <atomikos.version>3.9.3</atomikos.version> <bitronix.version>2.1.4</bitronix.version>

If we want to overwrite it, it will be easier, we just need to overwrite these attributes, and this time we use Thymeleaf to do the demonstration.

<thymeleaf.version>2.1. 6. Release</thymeleaf.version>
<thymeleaf-layout-dialect.version>1.4.0</thymeleaf-layout-dialect.version>

Above is the Springboot default version of the Thymealf, we just need to overwrite the property.

Let's first look at the version of the jar file that was introduced by default:

  

We find from the above dependency chart that it is really the version information defined in the attribute, and if you want to overwrite it, just add the following information.

<properties>    <thymeleaf.version>3.0.  2. release</thymeleaf.version>    <thymeleaf-layout-dialect.version>2.1.  1</thymeleaf-layout-dialect.version></properties>

We have found that we have covered the above version attribute in our own pom file.

We now find that the information of our thymeleaf has been overwritten.

[2] Overwrite version information among dependency managers

This approach is more troublesome than overwriting the version information in the parent POM.

We need to get rid of dependencies first and then join our own dependencies.

<dependencyManagement> <dependencies> <dependency> <groupid>org.s                Pringframework.boot</groupid> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.9.            Release</version> <type>pom</type> <scope>import</scope>                </dependency> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf</artifactId> <version>3.0.2. release</version> </dependency> <dependency> <groupid>org.thy Meleaf</groupid> <artifactId>thymeleaf-spring4</artifactId> <version&gt ;2.1.0</version> </dependency> </dependencies> </dependencyManagement>

What we're using here is to add the corresponding version of Thymeleaf in the dependency management, so that by relying on the principle of passing the declaration, we will overwrite the original thymeleaf content with high priority.

However, we need to manually add dependencies when we use them.

002 Dependency Management

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.