Spring Boot多modules的pom文件配置
2022-03-13 本文已影响0人
Jesse4023
一 创建一个maven项目作为父工程
1、删除src目录
2、修改pom文件,使用spring-boot-dependencies依赖对springboot的依赖包进行统一管理。
<modelVersion>4.0.0</modelVersion>
<!--基本信息-->
<groupId>com.jesse</groupId>
<artifactId>jessecloud</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>jessecloud</name>
<description> </description>
<!--定义属性值-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring.boot.version>2.5.6</spring.boot.version>
</properties>
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<!-- SpringBoot的依赖配置-->
<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>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>${oshi.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>framework</module>
<module>web</module>
</modules>
<!--编译管理 jdk版本和字符集编码-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
<!--Maven远程仓库设置 非必要,可以删除-->
<repositories>
<repository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<!--Maven远程插件库设置 非必要,可以删除-->
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
二 创建子工程
1、创建module之后,父工程pom自动添加<modules>关联
2、子工程pom.xml添加以下内容
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.jesse</groupId>
<artifactId>jessecloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<dependencies>
<!-- SpringBoot Web容器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 获取系统信息 -->
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
父工程的pom就像一个容器,里边放了各种的依赖,哪个子模块需要就在其pom里引用;