Maven管理多模块
Maven管理多模块
 Maven 管理多模块应用的实现是互联网项目中多使用分布式开发,那么每个独立的服务都会使用独立的项目进行维护,那么这样就需要使用多模块应用管理,来实现项目的高度统一。
- 设置父工程的 pom 文件
 父工程的 packaging 标签的文本内容必须设置为 pom

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

- 
创建子模块  
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>
本文来自博客园,作者:guoyuxin3,转载请注明原文链接:https://www.cnblogs.com/guoyuxin3/p/15456198.html

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号