注意所有依赖的版本一切以自己的项目为准,尤其是jdk、springboot、数据库连接池的选择。另外这里只做依赖管理,所以没有引入数据库驱动。
<packaging>标签要选择pom,同时需要在<modules>中管理自己的子模块。
如果需要更换版本,只用改变<properties>里对应版本号就行
<packaging>pom</packaging>
<modules>
<module>xx-xx-xx</module>
</modules>
<properties>
<!-- 项目所需jdk版本 -->
<java.version>1.8</java.version>
<!-- 项目所需SpringBoot版本 -->
<spring-boot.version>2.6.13</spring-boot.version>
<hutool.version>5.8.15</hutool.version>
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
<log4j.version>2.19.0</log4j.version>
<redisson.version>3.19.3</redisson.version>
<satoken.version>1.34.0</satoken.version>
<!-- 数据库连接池选择druid -->
<druid.version>1.2.16</druid.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- 相当于复制spring-boot-dependencies中的dependency到这里进行管理 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- log4j2适配slf4j包 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- log4j2核心包(包含slf4j) -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- log4j2核心包 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- 糊涂官网:https://hutool.cn/ -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<!-- MP官网:https://baomidou.com/-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!-- 使用redisson集成分布式锁等 -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>${redisson.version}</version>
</dependency>
<!-- Sa-Token 权限认证,在线文档:https://sa-token.cc -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<version>${satoken.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- lombok使代码耦合度增加、且需安装插件、JDK升级时它无法正常工作、开发过程中要求协作开发的其他团队人员也同步使用lombok. 这里引入方便简化代码,加入provided使其打包时失效 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source><!-- 指定源代码使用的JDK版本 -->
<target>${java.version}</target><!-- 指定class文件的编译版本 -->
<encoding>${project.build.sourceEncoding}</encoding><!-- 指定字符集编码 -->
</configuration>
</plugin>
<!-- -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<skip>true</skip> <!-- 为false将生成.jar.original文件(普通jar包,不包含依赖,不能直接java -jar 命令执行。一般用于给其他项目作依赖) -->
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- 表示从阿里云下载`项目依赖`的库文件 -->
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
<!-- 是否需要从远程仓库中下载稳定版本的构件 -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 是否需要从远程仓库中下载快照版本的构件 -->
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
若想将项目打包,只需在子项目的pom.xml中添加
<packaging>jar/war</packaging>
...
...
<build>
<plugins>
<!-- 在打Jar包时会引入依赖包一起打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<skip>true</skip> <!-- 为false将生成.jar.original文件(普通jar包,不包含依赖,不能直接java -jar 命令执行。一般用于给其他项目作依赖) -->
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>