Maven管理多模块

Maven管理多模块

​ Maven 管理多模块应用的实现是互联网项目中多使用分布式开发,那么每个独立的服务都会使用独立的项目进行维护,那么这样就需要使用多模块应用管理,来实现项目的高度统一。

  1. 设置父工程的 pom 文件
    父工程的 packaging 标签的文本内容必须设置为 pom

  1. 删除 src 目录
    父工程要求 src 目录必须删除掉

  1. 创建子模块

parent选择001-maven-parent

子模块目录也在001-maven-parent目录下

子模块的pom文件

<parent>
        <artifactId>001-maven-parent</artifactId>
        <groupId>com.g0rez</groupId>
        <version>1.0.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>002-maven-java</artifactId>

之后就可以通过父工程的pom文件管理依赖和插件

<properties >
        <junit-version>4.12</junit-version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit-version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

子模块申请使用依赖(子模块只需要提供groupId artifactId 版本号为父工程提供的版本号)

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
    </dependencies>

父项目管理插件

<!--  子模块无条件继承父工程了插件-->
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <!-- 插件的版本 -->
        <version>3.5.1</version>
        <!-- 编译级别 -->
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <!-- 编码格式 -->
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值