【maven实战】22-继承

maven聚合特性可以通过一条命令同时构建account-email和account-persist两个模块,但是这两个模块有着很多相同的配置,例如有相同的groupId和version,有相同的spring-core,spring-beans等和相同maven-compiler-plugin与maven-resources-plugin等插件配置。在maven中有机制让我们抽取出重复的配置这就是POM的继承。

以上篇博文为基础,在account-aggregator下创建一个名为account-parent的 子目录,然后在该子目录下建立一个所有除account-aggregator之外模块的父模块。为此在该子目录创建一个pom.xml文件如下:

<project>  
    <modelVersion>4.0.0</modelVersion>  
    <groupId>com.juvenxu.mvnbook.account</groupId>  
    <artifactId> account-parent </artifactId>  
    <version>1.0.0-SNAPSHOT</version>  
    <packaging>pom</packaging>  
    <name>Account Parent</name>  
</project>

有了父模块只是为了帮助消除配置的重复。首先将account-email的POM修改如下:

<project>  
    <modelVersion>4.0.0</modelVersion>  
    <parent>  
        <groupId>com.juvenxu.mvnbook.account</groupId>  
        <artifactId>account-parent</artifactId>  
        <version>1.0.0-SNAPSHOT</version>  
        <relativePath>../account-parent/pom.xml</relativePath>  
    </parent >  
    <artifactId>account-email</artifactId>  
    <name>Account Email</name>  
  ...  
</project>

account-persiste与上类型。为了节省篇幅上述POM中省略了依赖配置和插件配置,稍后会介绍如何将共同的依赖配置提取到父模块中。最后同样还需要把account-parent加入到聚合模块account-aggregator中如下:

<project>  
    <modelVersion>4.0.0</modelVersion>  
    <groupId>com.juvenxu.mvnbook.account</groupId>  
    <artifactId>account-aggregator</artifactId>  
    <version>1.0.0-SNAPSHOT</version>  
    <packaging> pom </packaging>  
    <name>Account Aggregator</name>  
    <modules>  
        <module>account-email</module>  
        <module>account-persist</module>  
        <module> account-parent</module>  
    </modules>  
</project>

Maven可继承的POM 元素:
groupId :项目组 ID ,项目坐标的核心元素;  
version :项目版本,项目坐标的核心元素;  
description :项目的描述信息;  
organization :项目的组织信息;  
inceptionYear :项目的创始年份;  
url :项目的 url 地址  
develoers :项目的开发者信息;  
contributors :项目的贡献者信息;  
distributionManagerment :项目的部署信息;  
issueManagement :缺陷跟踪系统信息;  
ciManagement :项目的持续继承信息;  
scm :项目的版本控制信息;  
mailingListserv :项目的邮件列表信息;  
properties :自定义的 Maven 属性;  
dependencies :项目的依赖配置;  
dependencyManagement :醒目的依赖管理配置;  
repositories :项目的仓库配置;  
build :包括项目的源码目录配置、输出目录配置、插件配置、插件管理配置等;  
reporting :包括项目的报告输出目录配置、报告插件配置等

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值