一、 新建工程和确定工程目录
在若依系统中Module分为
ruoyi-common
通用工具ruoyi-system
系统模块ruoyi-framework
核心模块ruoyi-admin
后台系统模块ruoyi-quartz
定时任务ruoyi-generator
代码生成
我的搭建项目分的模块为:
Gangbb-core
项目核心模块Gangbb-common
项目通用工具模块Gangbb-admin
后台管理模块
说明:
- 我把若依中的framework和system内容整合到了
Gangbb-core
中,个人认为没必要分出来。 - 定时任务和代码生成到最后才会涉及,先把项目基础的东西搞清楚再说!
Let’s go!
1. 新建Maven工程及多Module子工程
一、新建一个Maven工程
二、填写项目信息
三、删除一些新建Maven工程的不需要的文件
四、在该工程下新建子Module
五、填写子Module信息(也是一个Maven工程)
成果:
(对应pom.xml会自动写好子父对应关系)
PS:这里common写的时候拼错了,后续改过来了
六、重复第五步,完成其他子Module创建
除了Module名不同,其他操作都一样。
创建结果:
2. 编写pom.xml文件
一、父Gangbb-Vue的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--父工程项目信息-->
<groupId>com.gangbb</groupId>
<artifactId>Gangbb-Vue</artifactId>
<version>1.0.0</version>
<!--子工程声明-->
<modules>
<module>Gangbb-common</module>
<module>Gangbb-core</module>
<module>Gangbb-admin</module>
</modules>
<!--打包类型-->
<packaging>pom</packaging>
<properties>
<gangbb.version>1.0.0</gangbb.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<pagehelper.boot.version>1.3.0</pagehelper.boot.version>
</properties>
<!--统一项目整体依赖版本-->
<dependencyManagement>
<dependencies>
<!-- pagehelper 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.boot.version}</version>
</dependency>
<!-- SpringBoot的依赖配置 begin-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.12.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SpringBoot的依赖配置 end-->
<!--本项目自身Module begin-->
<!-- 项目核心模块-->
<dependency>
<groupId>com.gangbb</groupId>
<artifactId>Gangbb-core</artifactId>
<version>${gangbb.version}</version>
</dependency>
<!-- 项目通用工具模块-->
<dependency>
<groupId>com.gangbb</groupId>
<artifactId>Gangbb-common</artifactId>
<version>${gangbb.version}</version>
</dependency>
<!--本项目自身Module end-->
</dependencies>
</dependencyManagement>
<!--编译及打包项目配置-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
<!--依赖下载镜像源-->
<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>
<!--插件镜像源-->
<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>
</project>
注意点:
Maven中的
<dependencyManagement>
元素提供了一种管理依赖版本号的方式。在<dependencyManagement>
元素中声明所依赖的jar包的版本号等信息,那么所有子项目再次引入此依赖jar包时则无需显式的列出版本号。Maven会沿着父子层级向上寻找拥有<dependencyManagement>
元素的项目,然后使用它指定的版本号。关于
<type>pom</type> <scope>import</scope>
解释:
关于
<packaging>pom</packaging>
解释:
配置
<packaging>pom</packaging>
的意思是使用maven分模块管理,都会有一个父级项目,pom文件一个重要的属性就是packaging(打包类型),一般来说所有的父级项目的packaging都为pom,packaging默认类型jar类型,如果不做配置,maven会将该项目打成jar包。其他可填值:
pom ---------> 父类型都为pom类型
jar ---------> 内部调用或者是作服务使用
war ---------> 需要部署的项目
二、Gangbb-common的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>Gangbb-Vue</artifactId>
<groupId>com.gangbb</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Gangbb-common</artifactId>
<description>
common通用工具模块
</description>
</project>
三、Gangbb-core的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>Gangbb-Vue</artifactId>
<groupId>com.gangbb</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Gangbb-core</artifactId>
<description>
core框架核心模块
</description>
</project>