• 搭建统一的依赖管理


    概述

    依赖于一个二方库群时,必须定义一个统一的版本管理,避免版本号不一致。

    在企业项目开发中,一般都会有一个统一的依赖管理项目,来定义依赖的版本。项目开发的时候会依赖这个项目,所有的依赖的版本都统一定义在这个项目中。

    比如 SpringBoot 项目,Spring 定义了一个 spring-boot-dependencies 项目来统一管理 SpringBoot 相关的依赖版本,不同 SpringBoot 版本配置的依赖版本号可能不相同,但 RELEASE 版本的都会经过兼容性测试,以用于生产。

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>2.3.12.RELEASE</version>
      <packaging>pom</packaging>
      <name>spring-boot-dependencies</name>
      <description>Spring Boot Dependencies</description>
      <url>https://spring.io/projects/spring-boot</url>
      <licenses>
        <license>
          <name>Apache License, Version 2.0</name>
          <url>https://www.apache.org/licenses/LICENSE-2.0</url>
        </license>
      </licenses>
      <developers>
        <developer>
          <name>Pivotal</name>
          <email>info@pivotal.io</email>
          <organization>Pivotal Software, Inc.</organization>
          <organizationUrl>https://www.spring.io</organizationUrl>
        </developer>
      </developers>
      <scm>
        <url>https://github.com/spring-projects/spring-boot</url>
      </scm>
      <properties>
        <xxx.version>*.*.*</xxx.version>
        ...
      </properties>
    
      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>...</groupId>
            <artifactId>...</artifactId>
            <version>...</version>
          </dependency>
          ...
        </dependencies>
      </dependencyManagement>
    
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>...</groupId>
              <artifactId>...</artifactId>
              <version>...</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
      </build>
    </project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56

    所以我们也会定义一个 dependencies 项目,作为我们的统一的依赖管理项目,dependencies 是一个慢慢完善的依赖管理项目,我们可以将开发过程中用到的依赖的版本归纳到这个项目中,同时我们可以像 Spring 一样通过 dependencies 的版本来保证依赖版本之间的兼容性,比如:1.0.0-RELEASE 中的 fastjson 版本为 1.2.761.1.0-RELEASE 中的 fastjson 版本为 2.0.2

    dependencies

    SpringCloud 版本如何选择 这篇文章中,我们确定了 SpringBootSpringCloudSpringCloudAlibaba 等核心框架的版本,所以我们的 pom.xml 文件定义为:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.example</groupId>
        <artifactId>dependencies</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>pom</packaging>
        <description>通用的依赖管理</description>
    
        <properties>
        	<java.version>1.8</java.version>
            <maven.compiler.source>${java.version}</maven.compiler.source>
            <maven.compiler.target>${java.version}</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    
            <spring-boot.version>2.3.12.RELEASE</spring-boot.version>
            <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
            <spring-cloud-alibaba.verion>2.2.7.RELEASE</spring-cloud-alibaba.verion>
        </properties>
    
        <dependencyManagement>
            <dependencies>
                <!-- Spring Boot -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-dependencies</artifactId>
                    <version>${spring-boot.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
    
                <!-- Spring Cloud -->
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring-cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
    
                <!-- Spring Cloud Alibaba -->
                <dependency>
                    <groupId>com.alibaba.cloud</groupId>
                    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                    <version>${spring-cloud-alibaba.verion}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
  • 相关阅读:
    MySQL-创建用户、赋权限
    目前的网络情况与特点
    监控服务器体系
    leetcode中级2,Sorting and Searching:347. 前 K 个高频元素
    pandas plot函数:数据可视化的快捷通道
    Godot导出Windows版本图标未更换的问题
    docker/ nvidia-docker
    算法与数据结构 - 排序算法(python实现)
    力扣240.搜索二维矩阵II
    博途PLC浮点数拆分为高低16位字(AT覆盖指令应用)
  • 原文地址:https://blog.csdn.net/qiaohao0206/article/details/125512099