温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在Idea中创建一个多模块maven聚合项目

发布时间:2021-03-10 17:09:36 来源:亿速云 阅读:231 作者:Leah 栏目:编程语言

怎么在Idea中创建一个多模块maven聚合项目?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

1.怎么理解maven的继承和聚合

maven多模块项目通常由一个父模块和若干个子模块构成,每个模块都对应着一个pom.xml。它们之间通过继承和聚合(也称作多模块)相互关联。多模块适用于一些比较大的项目,通过合理的模块拆分,实现代码的复用,便于维护和管理。
继承:和java中的继承有点类似,就是父pom.xml声明的版本和引用的jar,子模块可以不用再引用直接调用。
聚合:父模块包含多个子模块就是聚合,多个子模块之间可以调用,但是要注意关系,不要两个互相依赖,这样做的好处就是可以通过一条命令进行构建

注意:

groupId是项目组织唯一的标识符,实际对应JAVA的包的结构,artifactId是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称。groupId一般分为多个段,一般第一段为域,第二段为公司名称,第三段通常为项目名称。

2.Idea创建多模块项目

2.1创建父模块(空的maven项目)

怎么在Idea中创建一个多模块maven聚合项目

怎么在Idea中创建一个多模块maven聚合项目

怎么在Idea中创建一个多模块maven聚合项目

怎么在Idea中创建一个多模块maven聚合项目

pom.xml配置
<modelVersion>4.0.0</modelVersion> 
<parent> 
 <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-parent</artifactId> 
 <version>2.1.6.RELEASE</version> 
</parent> 
 
<groupId>cn.yskcoder.fire</groupId> 
<artifactId>fire</artifactId> 
<packaging>pom</packaging> 
<version>v1.0</version> 
 
 
<modules> 
 <module>fire-common</module> 
 <module>fire-dao</module> 
 <module>fire-service</module> 
 <module>fire-web</module> 
</modules> 
 
<properties> 
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
 <java.version>1.8</java.version> 
 <spring-boot.version>2.1.6.RELEASE</spring-boot.version> 
 
</properties>

2.2.创建工具类(common)模块(dao、service同这个操作一样)

怎么在Idea中创建一个多模块maven聚合项目

怎么在Idea中创建一个多模块maven聚合项目

怎么在Idea中创建一个多模块maven聚合项目

pom.xml配置
<modelVersion>4.0.0</modelVersion> 
<parent> 
 <artifactId>fire</artifactId> 
 <groupId>cn.yskcoder.fire</groupId> 
 <version>v1.0</version> 
</parent> 
 
<!--模块信息--> 
<packaging>jar</packaging> 
<name>fire-common</name> 
<artifactId>fire-common</artifactId> 
<description>fire 通用工具类模块</description> 
 
<!--模块依赖--> 
<dependencies> 
 
</dependencies>

2.3.创建数据库访问(dao)模块(只贴pom.xml代码)

<modelVersion>4.0.0</modelVersion> 
<parent> 
 <artifactId>fire</artifactId> 
 <groupId>cn.yskcoder.fire</groupId> 
 <version>v1.0</version> 
</parent> 
 
<!--模块信息--> 
<packaging>war</packaging> 
<name>fire-web</name> 
<artifactId>fire-web</artifactId> 
<description>fire web模块</description> 
 
<!--模块依赖--> 
<dependencies> 
 <dependency> <groupId>cn.yskcoder.fire</groupId> 
 <artifactId>fire-service</artifactId> 
 <version>v1.0</version> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-web</artifactId> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-aop</artifactId> 
 </dependency> 
 <dependency> <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-test</artifactId> 
 <scope>test</scope> 
 </dependency> 
</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> 
   </configuration> 
  </plugin>
 </plugins>
 <resources> 
  <resource> 
  <directory>src/main/webapp</directory> 
  <filtering>false</filtering> 
  </resource> 
  <resource> 
   <directory>src/main/resources</directory> 
   <filtering>true</filtering> 
  </resource> 
 </resources>
</build>

3.Idea打包多模块项目

clean package -Dmaven.test.skip=true

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI