maven 父子模块

父子模块的pom文件里会涉及dependencies、dependecyManagement、packaging元素、properties元素。

子模块里必须有parent元素,如下所示:

<parent>
        <groupId>org.apache</groupId>
        <artifactId>plugin</artifactId>
        <version>1.3.0-SNAPSHOT</version>
</parent>

父模块里会有modules元素,如下所示:

<modules>
        <module>provider</module>
        <module>consumer</module>
        <module>api</module>
</modules>

1、packaging元素

父模块里的packaging必须是pom。子模块一般是jar,但也可以是pom,此时子模块仅包含一些依赖,没有代码,或者也是父模块。


2、dependencies元素

一般出现在父模块的pom文件里。dependencies包含的依赖会被子项目无条件继承下去,无需子项目显示指定。用法如下所示:

<dependencies>
       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
</dependencies>


3、dependecyManagement元素

一般出现在父模块的pom文件里。dependencyManagement包含的依赖不会被子项目直接继承下去,子项目需要显示写出依赖,当然可以省略versionscope(从父项目中继承)。用法如下:

<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-test</artifactId>
				<version>${spring.version}</version>
			</dependency>
		</dependencies>
</dependencyManagement>


4、mvn命令

在父项目的根目录下执行mvn clean compile,那么该父项目及其子项目都会被先清理再编译,并且是按照实际的依赖关系对子模块重排序,以确保所有模块都能顺利完成构建(参见http://blog.csdn.net/eclipser1987/article/details/5739177)。


5、properties元素

properties元素通常用来定义一些常量,会被子模块无条件的继承过去。可用来定义版本号,这样可以同时修改多个依赖的版本号。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值