关于Maven中pom文件标签的详解,分别对比父工程pom文件与子工程pom文件。

一、介绍

这里我们以若依开源框架为例,我们先讲解,父工程pom文件,之后再讲解子工程pom文件。

首先,我们先介绍若依前后端分离项目的目录结构;
在这里插入图片描述

一、父工程pom.文件

在这里插入图片描述父工程pom文件注释:(每个标签,只注释一次,相同标签不重复介绍)

1、声明该pom文件所采用的xml版本为1.0(也就是页面所采用的标签格式,解析的时候也按照相应的格式进行解析:例如我们看到 x+y=z;按照我们的逻辑就是x加y=z;而不会把其理解为其他逻辑;如果是别的版本中,那么x+y=z的逻辑,就不一定是x+y=z,可能是别的相应符号所标识或者相应表达式)感兴趣的可以去SSM学习章节具体学习一下文件约束相关协议;
2、encoding="UTF-8"? 的含义表示,我们pom.xml文件页面中,中文采用的是utf-8编码方式,在展示的过程中,我们也要按照utf-8格式进行解析,例如utf-8一个中文汉字为2个字节;gbk一个汉字为3个字节,那么如果我们页面中采用的是utf-8编码方式 有2个连续的汉字 占用4个字节,解析的时候按照6个字节所解析,那么必定会造成乱码。
<?xml version="1.0" encoding="UTF-8"?>


3、project是pom文件的根元素  是标签:根标签,表示对当前工程进行配置、管理
<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">


4、描述pom文件遵循从哪个版本的项目描述符  modelVersion 标签:从Maven 2 开始就固定为4.0.0
     <!--代表当前pom.xml 所采用对标签结构-->
	<modelVersion>4.0.0</modelVersion>
	
5、坐标信息   范围从大到小    groupId > artifactId > version

  5.1 groupId描述项目组织的唯一标识,也就是项目是哪个公司或者组织开发的,通常使用域名或组织名称
    <groupId>com.ruoyi</groupId>
  5.2 artifactId项目唯一标识,通常使用项目或模块名     如果一个项目中有多个工程,在代表项目下面对一个模块 
    <artifactId>ruoyi</artifactId>
  5.3 version项目版本号
    <version>3.8.4</version>
   6. 项目名称
    <name>ruoyi</name>
   7. 项目地址
    <url>http://www.ruoyi.vip</url>
   8. 项目详情
    <description>若依管理系统</description>

   9.对项目的一些属性进行定于,这个属性可以是自定义属性
    <properties>
        自定义属性标签,标签名,就是属性名称,标签值就是属性值, 可以通过${标签名}的方式引用其所对应的值
        <ruoyi.version>3.8.4</ruoyi.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
        <druid.version>1.2.15</druid.version>
        <bitwalker.version>1.21</bitwalker.version>
        <swagger.version>3.0.0</swagger.version>
        <kaptcha.version>2.3.3</kaptcha.version>
        <pagehelper.boot.version>1.4.6</pagehelper.boot.version>
        <fastjson.version>2.0.20</fastjson.version>
        <oshi.version>6.4.0</oshi.version>
        <commons.io.version>2.11.0</commons.io.version>
        <commons.fileupload.version>1.4</commons.fileupload.version>
        <commons.collections.version>3.2.2</commons.collections.version>
        <poi.version>4.1.2</poi.version>
        <velocity.version>2.3</velocity.version>
        <jwt.version>0.9.1</jwt.version>
    </properties>
	
Maven 可以通过(一般父工程中才有dependencyManagement ) dependencyManagement 元素对依赖进行管理,它具有以下 2 大特性:
在该元素下声明的依赖不会实际引入到模块中(子模块),只有在 (子模块)dependencies 元素下同样声明了该依赖,才会引入到模块中。
该元素能够约束 dependencies 下依赖的使用,即(子模块) dependencies 声明的依赖若未指定版本,则使用 (父工程)dependencyManagement 中指定的版本,(如果子模块中指定了版本)否则将覆盖(父工程中) dependencyManagement 中的版本。
    <dependencyManagement>
     9.1 引入Jar依赖列表 dependencies标签:配置具体依赖信息,可以包含多个 
       dependency 子标签
        <dependencies>
            9.2  <!--配置一个具体的依赖信息-->
            <!-- SpringBoot的依赖配置-->
            <dependency>
            9.3 坐标信息:导入那个jar包,就引入什么坐标
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.5.14</version>
            9.5     
               9.5.1 Maven中有2种方法可以,避免重复造轮子,一种是继承,另外一种是引用;
               9.5.2 继承就是,就是若依项目中(也就是本文所举例)父工程中,定义dependencyManagement
                而子工程不需要写版本号,直接继承父工程版本号,当然如果子工程也写版本号,那么会使用自己的版本号;
               9.5.3 引用与继承有些类似,不过确是,我们父工程要引用 原始起步依赖,那么我们父工程这个依赖类型要与原始依赖类型要一致,比如引入的是一个java工程,那么type 类型就应该是jar,也就是默认类型,可以不写,在本文中我们引入是spring-boot-dependencies这个Maven工程依赖,其原始类型是pom类型,所以我们这里必须写pom类型,并且要配合<scope>import</scope>标签所使用。相当于把依赖复制过来,而不是进行继承。
                <type>pom</type>
                
             9.4 该jar包的作用域 一共6种
                <!--如果不设置scope标签,m默认值就是compile
               test 当前依赖仅参与项目的单元测试
               runtime 当前依赖仅参与项目的运行阶段
               provided 与compile 类似,区别在与不会参与项目的最终打包
               system 从本地磁盘中引用一个jar包
            -->
            <!--如果作用于是system,那么还需要额外加入一个标签,如下-->

                <scope>import</scope>
            </dependency>

            <!-- 阿里数据库连接池 -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
                <version>${druid.version}</version>
            </dependency>

            <!-- 解析客户端操作系统、浏览器等 -->
            <dependency>
                <groupId>eu.bitwalker</groupId>
                <artifactId>UserAgentUtils</artifactId>
                <version>${bitwalker.version}</version>
            </dependency>

            <!-- 系统模块-->
            <dependency>
                <groupId>com.ruoyi</groupId>
                <artifactId>ruoyi-system</artifactId>
                <version>${ruoyi.version}</version>
            </dependency>

          

        </dependencies>
    </dependencyManagement>

    10.定义子模块
    <modules>
    限于篇幅我把一些子工程剔除了。这篇文章主要是让大家明白标签结构和引用关系的。
        <module>ruoyi-admin</module>
        <module>ruoyi-system</module>
    </modules>
    11.打包方式必须为pom方式,父工程固定写法
    <packaging>pom</packaging>


    <dependencies>

    </dependencies>

    <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>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>public</id>
            <name>aliyun nexus</name>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

二、子工程pom文件
在这里插入图片描述

子工程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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>ruoyi</artifactId>
        <groupId>com.ruoyi</groupId>
        <version>3.8.4</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <artifactId>ruoyi-admin</artifactId>

    <description>
        web服务入口
    </description>

    <dependencies>

        <!-- spring-boot-devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 表示依赖不会传递 -->
        </dependency>
         

        <!-- swagger3-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
        </dependency>

        <!-- 防止进入swagger页面报类型转换错误,排除3.0.0中的引用,手动增加1.6.2版本 -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.6.2</version>
        </dependency>

         <!-- Mysql驱动包 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <!-- 核心模块-->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-framework</artifactId>
        </dependency>

        <!-- 定时任务-->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-quartz</artifactId>
        </dependency>

        <!-- 代码生成-->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-generator</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.1.RELEASE</version>
                <configuration>
                    <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>   
                <groupId>org.apache.maven.plugins</groupId>   
                <artifactId>maven-war-plugin</artifactId>   
                <version>3.1.0</version>   
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <warName>${project.artifactId}</warName>
                </configuration>   
           </plugin>   
        </plugins>
        <finalName>${project.artifactId}</finalName>
    </build>

</project>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Code攻城狮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值