maven多模块下dependencyManagement的pom依赖问题

1. 多模块项目

在实际开发过程中,会使用多模块的项目搭建,因此就会存在一个顶级项目,以及模块项目。

通常顶级项目也就是父类项目,是会删除其src文件夹,保留pom文件,通常作为各个模块的依赖的jar的管理。

2. 继承父级依赖dependencies

如果在父级项目中的pom文件中

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>xxx</version>
         </dependency>
     </dependencies>

其他的模块都是会自动导入该模块。

3. 管理依赖版本dependencyManagement

在顶级父类pom文件中

<dependencyManagement>
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>xxx</version>
         </dependency>
     </dependencies>
</dependencyManagement>

这里的依赖仅仅是被声明了,也就是定义了一个依赖配置类,如果子模块需要使用到该依赖的时候,只需要编写groupid和artifactid即可,无需定义version,因为父类中定义好了。

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
     </dependencies>

4. 其他

如果使用idea创建一个单独无模块的项目的时候,会自动在pom文件指定父级项目。

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

因此在生成的pom文件中,有些依赖是没有加version的,因为是可以在其父类中的dependencyManagement找到。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Maven权威指南 Authors Tim O'Brien (Sonatype, Inc.) , John Casey (Sonatype, Inc.) , Brian Fox (Sonatype, Inc.) , Bruce Snyder () , Jason Van Zyl (Sonatype, Inc.) , Juven Xu () Abstract Maven权威指南是一本关于Apache Maven的书。 Copyright 1. Creative Commons BY-ND-NC Foreword: Beta 0.16 Preface 1. How to Use this Book 2. Your Feedback 3. Font Conventions 4. Maven Writing Conventions 5. Acknowledgements 1. 介绍 Apache Maven 1.1. Maven... 它是什么? 1.2. 约定优于配置(Convention Over Configuration) 1.3. 一个一般的接口 1.4. 基于Maven插件的全局性重用 1.5. 一个“项目”的概念模型 1.6. Maven是Ant的另一种选择么? 1.7. 比较Maven和Ant 1.8. 总结 2. 安装和运行Maven 2.1. 验证你的Java安装 2.2. 下载Maven 2.3. 安装Maven 2.3.1. 在Mac OSX上安装Maven 2.3.2. 在Microsoft Windows上安装Maven 2.3.3. 在Linux上安装Maven 2.3.4. 在FreeBSD或OpenBSD上安装Maven 2.4. 验证Maven安装 2.5. Maven安装细节 2.5.1. 用户相关配置和仓库 2.5.2. 升级Maven 2.6. 获得Maven帮助 2.7. 使用Maven Help插件 2.7.1. 描述一个Maven插件 2.8. 关于Apache软件许可证 I. Maven实战 3. 一个简单的Maven项目 3.1. 简介 3.1.1. 下载本章的例子 3.2. 创建一个简单的项目 3.3. 构建一个简单的项目 3.4. 简单的项目对象模型 (Project Object Model) 3.5. 核心概念 3.5.1. Maven插件和目标 (Plugins and Goals) 3.5.2. Maven生命周期 (Lifecycle) 3.5.3. Maven坐标 (Coordinates) 3.5.4. Maven仓库(Repositories) 3.5.5. Maven依赖管理 (Dependency Management) 3.5.6. 站点生成和报告 (Site Generation and Reporting) 3.6. 小结 4. 定制一个Maven项目 4.1. 介绍 4.1.1. 下载本章样例 4.2. 定义Simple Weather项目 4.2.1. Yahoo! Weather RSS 4.3. 创建Simple Weather项目 4.4. 定制项目信息 4.5. 添加新的依赖 4.6. Simple Weather源码 4.7. 添加资源 4.8. 运行Simple Weather项目 4.8.1. Maven Exec 插件 4.8.2. 浏览你的项目依赖 4.9. 编写单元测试 4.10. 添加测试范围依赖 4.11. 添加单元测试资源 4.12. 执行单元测试 4.12.1. 忽略测试失败

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值