现在的位置: 首页 > 编程语言 > 正文

Idea创建多模块maven聚合项目的实现

2020年02月13日 编程语言 ⁄ 共 2954字 ⁄ 字号 评论关闭

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

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

注意:

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

2.Idea创建多模块项目

2.1创建父模块(空的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同这个操作一样)

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

接下来有空会继续更新这个项目https://github.com/yskcoder/Fire

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

本文标题: Idea创建多模块maven聚合项目的实现

以上就上有关Idea创建多模块maven聚合项目的实现的相关介绍,要了解更多Idea,多模块maven,Idea,多模块maven聚合内容请登录学步园。

抱歉!评论已关闭.