maven的聚合与继承

----继承

user-parent pom.xml文件中是使用<dependencyManagement>标签来管理子类可能用到的依赖包。注意父类项目的打包方式是<packaging>pom</packaging>


<!-- 父类中对依赖包的管理 -->
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>${junit.version}</version>
				<scope>test</scope>
			</dependency>
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>javax.servlet-api</artifactId>
				<version>3.0.1</version>
				<!-- 不会被打包 -->
				<scope>provided</scope>
			</dependency>
			<dependency>
				<groupId>javax.servlet.jsp</groupId>
				<artifactId>jsp-api</artifactId>
				<version>2.2</version>
				<scope>provided</scope>
			</dependency>
	</dependencyManagement>

子项目中使用parent标签来继承。

<!-- 使用parent标签来配置继承关系 -->
  <parent>
  	<groupId>org.mgang</groupId>
  	<artifactId>user-parent</artifactId>
  	<version>0.0.1-SNAPSHOT</version>
  	<relativePath>../user-parent/pom.xml</relativePath>
  </parent>

子项目中使用到的依赖只需要自定GAV中的GA,也就是groupIdartifactId。这样做的好处是让maven来管理jar包,可以避免包的冲突。

<dependencies>
   		<dependency>
			<groupId>org.json</groupId>
			<artifactId>json</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
		</dependency>
  </dependencies>

----聚合

在父类的pom.xml中使用modules来聚合子模块。

<!-- 将项目的模块jar,聚合 -->
	<modules>
		<module>../user-action</module>
		<module>../user-core</module>
		<module>../user-dao</module>
	</modules>

聚合后,只需要运行user-parent,也就是父项目的pom.xml命令mvn clean install,就会将聚合的项目模块也执行响应操作。







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值