pom非常好用的写法,统一管理springboot有关依赖的版本

发布时间 2023-05-10 11:16:29作者: 纯情旺仔

相信大家使用maven的时候,每引用一个依赖都要写一遍版本号,当然这是必要的,现在springboot非常的主流,每个springboot有关的依赖的版本又是一至的

我们大家就不需要重新去再写一遍了,可以引入依赖 spring-boot-dependencies,这样后面所有的有关springboot的依赖都使用的是 spring-boot-depencies的依赖

  <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <hutool-version>5.8.18</hutool-version>
        <spring-boot-version>2.2.2.RELEASE</spring-boot-version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>cn.hutool</groupId>
                <artifactId>hutool-all</artifactId>
                <version>${hutool-version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot-version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

我们来看看对比,原来的:

 

使用了spring-boot-dependencies 依赖之后

这样代码看着更加的简洁,后期也更易维护,学到了吗家人们