maven模块化管理

将一个大项目拆分成若干个子模块,方便项目管理维护、扩展,也方便模块间的相互引用,资源共享

具体步骤

先创建一个空项目(父项目)即下图的sky-take-out,然后打开项目结构的模块,选中父模块,再点+,

如果是导入模块,则导入对应模块的pom.xml文件

我们来看一下父工程的pom文件

  • parent表示父工程
  • 第11-14行本项目的坐标
  • modules表示本项目的子模块
  • properties管理依赖的版本
xml 复制代码
<dependency>
	<groupId>org.mybatis.spring.boot</groupId>
	<artifactId>mybatis-spring-boot-starter</artifactId>
	<version>${mybatis.spring}</version>
</dependency>

子模块可以引用同一父工程的其他子模块,这些被引用的子模块一般是可复用的公共模块,比如这里的pojo封装实体类对象,common封装各种工具类对象

dependencies和dependencyManagement

父工程使用 dependencies直接声明依赖,子工程会自动继承父工程的依赖,无需重复声明。子工程的 pom.xml 不需要再写这个依赖。

xml 复制代码
<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
  </dependency>
</dependencies>

父工程使用 dependencyManagement管理依赖,子工程不会自动继承这些依赖!必须显式声明需要的依赖,但可以省略version和 scope

父工程

xml 复制代码
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

子工程·

xml 复制代码
<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
  </dependency>
</dependencies>
相关推荐
前行的小黑炭10 分钟前
Android 协程的使用:结合一个环境噪音检查功能的例子来玩玩
android·java·kotlin
李少兄44 分钟前
解决IntelliJ IDEA 提交代码时无复选框问题
java·ide·intellij-idea
cyforkk1 小时前
Spring Boot @RestController 注解详解
java·spring boot·后端
叫我阿柒啊2 小时前
从Java全栈到前端框架:一次真实面试的深度复盘
java·spring boot·typescript·vue·database·testing·microservices
点云SLAM2 小时前
C++ 常见面试题汇总
java·开发语言·c++·算法·面试·内存管理
sniper_fandc2 小时前
IDEA修改系统缓存路径,防止C盘爆满
java·ide·intellij-idea
aristo_boyunv2 小时前
拦截器和过滤器(理论+实操)
java·数据仓库·hadoop·servlet
半夏陌离2 小时前
SQL 入门指南:排序与分页查询(ORDER BY 多字段排序、LIMIT 分页实战)
java·前端·数据库
CUIYD_19892 小时前
Eclipse 常用搜索功能汇总
java·ide·eclipse
野犬寒鸦3 小时前
力扣hot100:相交链表与反转链表详细思路讲解(160,206)
java·数据结构·后端·算法·leetcode