1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Idea创建多模块maven聚合项目

Idea创建多模块maven聚合项目

时间:2021-02-28 07:44:58

相关推荐

Idea创建多模块maven聚合项目

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

接下来有空会继续更新这个项目

/yskcoder/Fire

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。