目录
一、创建dependencyManagement标签
二、 将需要版本控制的依赖版本进行标签设置
三、将需要版本控制的依赖从各子模块迁移到此处
四、将父模块的依赖版本控制
五、删除子模块的全部版本
1、bocai-web-management模块
2、bocai-utils模块
六、打包
1、确定代码都可执行,无错误
2、bocai-parent加入标签
3、完整的bocai-parent的pom
3、打包
七、使用jar启动服务
前言:结合上篇《【java】【重构一】分模块开发设计实战》,进行版本锁定,明确dependencyManagement与dependencies区别
一、创建dependencyManagement标签
在父模块创建dependencyManagement以及dependencies
<!-- 7、 版本锁定 -->
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
二、 将需要版本控制的依赖版本进行标签设置
springboot项目无需控制
<properties>
<java.version>1.8</java.version>
<!-- 8、自定义属性 -->
<lombok.version>1.18.24</lombok.version>
<aliyun-sdk-oss.version>3.15.1</aliyun-sdk-oss.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<activation.version>1.1.1</activation.version>
<jaxb-runtime.version>2.3.3</jaxb-runtime.version>
<mybatis.version>2.3.1</mybatis.version>
<mysql-connector-j.version>8.0.31</mysql-connector-j.version>
<pagehelper.version>1.4.6</pagehelper.version>
<fastjson.version>1.2.76</fastjson.version>
<jjwt.version>0.9.0</jjwt.version>
<!-- 无需配置,因为springboot已经版本控制了 -->
<!--
<spring-boot-starter-test.version>2.7.5</spring-boot-starter-test.version>
<spring-boot-starter-aop.version>2.7.5</spring-boot-starter-aop.version>
<spring-boot-starter-web.version>2.7.5</spring-boot-starter-web.version>
-->
</properties>
三、将需要版本控制的依赖从各子模块迁移到此处
使用第二步设置的标签进行版本控制
<!-- 7、 版本锁定 -->
<dependencyManagement>
<dependencies>
<!-- 阿里云OSS依赖-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>${aliyun-sdk-oss.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>${activation.version}</version>
</dependency>
<!-- no more than 2.3.3-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-runtime.version}</version>
</dependency>
<!--JWT令牌-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<!-- mybatis起步依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
<version>${mysql-connector-j.version}</version>
</dependency>
<!-- PageHelper分页插件https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!--fastJSON-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- 100、 无需配置,因为在springboot当中已经版本控制了 -->
<!-- web起步依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot-starter-web.version}</version>
</dependency>
-->
<!-- springboot单元测试
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>${spring-boot-starter-test.version}</version>
</dependency>
-->
<!--AOP
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>${spring-boot-starter-aop.version}</version>
</dependency>
-->
</dependencies>
</dependencyManagement>
四、将父模块的依赖版本控制
<dependencies>
<!-- 6、 加入的公共依赖 -->
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!-- 4、注释以下依赖 -->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
-->
</dependencies>
五、删除子模块的全部版本
1、bocai-web-management模块
<!-- 3、加入 子模块依赖 -->
<dependency>
<groupId>com.bocai</groupId>
<artifactId>bocai-entity</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.bocai</groupId>
<artifactId>bocai-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- 4、加入依赖 -->
<!-- web起步依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- mybatis起步依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<!-- springboot单元测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- PageHelper分页插件https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<!--fastJSON-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<!--AOP-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>
2、bocai-utils模块
<dependencies>
<!-- 2、 注释 junit -->
<!--
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
-->
<!-- 3、加入依赖 -->
<!-- web起步依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 阿里云OSS依赖-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</dependency>
<!-- no more than 2.3.3-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<!--JWT令牌-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
</dependency>
</dependencies>
六、打包
1、确定代码都可执行,无错误
略
2、bocai-parent加入<modules>标签
如果你是创建模块时选择了父Parent,是自动生成的
<!-- 8、 聚合 打包 这个是创建模块选择 父的时候自动创建的-->
<modules>
<module>../bocai-entity</module>
<module>../bocai-utils</module>
<module>../bocai-web-management</module>
</modules>
3、完整的bocai-parent的pom
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- 1、修改为2.7.5 -->
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.bocai</groupId>
<artifactId>bocai-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 2、新增设置打包模式为pom -->
<packaging>pom</packaging>
<!-- 8、 聚合 打包 这个是创建模块选择 父的时候自动创建的-->
<modules>
<module>../bocai-entity</module>
<module>../bocai-utils</module>
<module>../bocai-web-management</module>
</modules>
<!-- 3、注释 name与description -->
<!--<name>bocai-parent</name>
<description>bocai-parent</description>-->
<properties>
<java.version>1.8</java.version>
<!-- 8、自定义属性 -->
<lombok.version>1.18.24</lombok.version>
<aliyun-sdk-oss.version>3.15.1</aliyun-sdk-oss.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<activation.version>1.1.1</activation.version>
<jaxb-runtime.version>2.3.3</jaxb-runtime.version>
<mybatis.version>2.3.1</mybatis.version>
<mysql-connector-j.version>8.0.31</mysql-connector-j.version>
<pagehelper.version>1.4.6</pagehelper.version>
<fastjson.version>1.2.76</fastjson.version>
<jjwt.version>0.9.0</jjwt.version>
<!-- 无需配置,因为springboot已经版本控制了 -->
<!--
<spring-boot-starter-test.version>2.7.5</spring-boot-starter-test.version>
<spring-boot-starter-aop.version>2.7.5</spring-boot-starter-aop.version>
<spring-boot-starter-web.version>2.7.5</spring-boot-starter-web.version>
-->
</properties>
<dependencies>
<!-- 6、 加入的公共依赖 -->
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!-- 4、注释以下依赖 -->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
-->
</dependencies>
<!-- 7、 版本锁定 -->
<dependencyManagement>
<dependencies>
<!-- 阿里云OSS依赖-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>${aliyun-sdk-oss.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>${activation.version}</version>
</dependency>
<!-- no more than 2.3.3-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-runtime.version}</version>
</dependency>
<!--JWT令牌-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<!-- mybatis起步依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
<version>${mysql-connector-j.version}</version>
</dependency>
<!-- PageHelper分页插件https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!--fastJSON-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- 100、 无需配置,因为在springboot当中已经版本控制了 -->
<!-- web起步依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot-starter-web.version}</version>
</dependency>
-->
<!-- springboot单元测试
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>${spring-boot-starter-test.version}</version>
</dependency>
-->
<!--AOP
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>${spring-boot-starter-aop.version}</version>
</dependency>
-->
</dependencies>
</dependencyManagement>
<!-- 5、注释 build -->
<!--
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
-->
</project>
3、打包
选择父bocai-parent 生命周期的package
七、使用jar启动服务
这里有个关键是bocai-web-management的pom需要build标签
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
#cmd窗口
java -jar 打包的jar包