iDEA 创建聚合工程
参考项目 :https://segmentfault.com/a/1190000011367492#articleHeader3
项目在整合后,可以完成基本的数据库访问 地址:https://github.com/sun2955/spring-test-study/tree/master/s_parent
在项目的开发中,随着项目的开发越来越多,也会遇上一些问题,开发一个接口服务,和一个后台,
如果写到一个项目里面,每次更新后台,接口的服务就会停,如果分成两个项目,那么如果遇上字段变更,不就得两个项目分别加字段,
于是这里就到了聚合工程的好处了.一个父工程下,管理子模块.子项目之间可以相互调调用,把通用的放在一个独立的项目中.供后台和接口服务通用
第一步:创建一个父工程,

删除其他的东西,保留pom.xml就够了

第二步:创建子模块,
如果只是创建通用模块,如common的时候,可以直接创建maven项目,会直接有父子结构,


这里创建四个项目

s_api -> spring Initializr 创建
s_common -> maven 创建
s_web -> spring Initializr 创建
s_core -> spring Initializr 创建
第三步:
修改父工程()的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.parent</groupId>
<artifactId>s_parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>s_parent</name>
<description>Demo project for Spring Boot</description>
<!-- 模块说明:这里声明多个子模块 -->
<modules>
<module>s_common</module>
<module>s_web</module>
<module>s_core</module>
<module>s_api</module>
</modules>
<properties>
<java.version>1.8</java.version>
</properties>
<!-- 版本说明:这里统一管理依赖的版本号 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.42</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
修改子模块,继承子父模块,本身的xml里面引用本项目的需要的jar就行,默认继承父工程的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>com.parent</groupId>
<artifactId>s_parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.web</groupId>
<artifactId>s_web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>s_web</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<!--本项目用到的模块-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这里测试下引用是否正常,在父项目中引入s_common,然后在继承项目中进行调用,如果能调用成功,说明子项目继承父项目的引用.

父项目在pom.xml中引入.

运行项目:

到这里,基本的聚合工程创建完毕.
浙公网安备 33010602011771号