Maven 中的继承与聚合
2017-07-13 11:09
337 查看
先贴一个parent 模块的pom.xml
子模块的pom.xml
继承:
1.子模块可以继承parent中所有关于GAV的属性,artifactId除外
2.子模块可以继承parent中properties
3.子模块可以继承parent中的dependencies,比如子模块都不用再添加log4j的依赖了,
但是这样也容易导致子模块中添加了不需要的模块。此时需要使用dependencyManagement,子模块pom.xml中只需要添加GA,这样也省去了很多麻烦。
聚合:
将所有开放的子模块使用modules打包,这样就不需要每个模块单独编译,打包了。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.myproject</groupId> <artifactId>myproject-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>myproject-parent</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>3.2.6.RELEASE</spring.version> </properties> <modules> <module>../example</module> </modules> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <!--for org.hamcrest.Matchers--> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-library</artifactId> <version>1.3</version> <scope>test</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> </project>
子模块的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.mycompany.myproject</groupId> <artifactId>myproject-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <relativePath>../myproject-parent/pom.xml</relativePath> </parent> <artifactId>peter-user</artifactId> <packaging>war</packaging> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>or b2e3 g.springframework</groupId> <artifactId>spring-core</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> </dependencies> </project>
继承:
1.子模块可以继承parent中所有关于GAV的属性,artifactId除外
2.子模块可以继承parent中properties
3.子模块可以继承parent中的dependencies,比如子模块都不用再添加log4j的依赖了,
但是这样也容易导致子模块中添加了不需要的模块。此时需要使用dependencyManagement,子模块pom.xml中只需要添加GA,这样也省去了很多麻烦。
聚合:
将所有开放的子模块使用modules打包,这样就不需要每个模块单独编译,打包了。
相关文章推荐
- maven 为何要模块划分-聚合/继承
- 04_Maven核心_POM_聚合与继承
- Maven的聚合和继承
- Maven详解之聚合与继承
- maven的聚合与继承
- Maven聚合与继承
- Maven聚合与继承
- 【Maven】Eclipse下Maven工程多模块继承和聚合创建
- Maven 的聚合和继承
- 【Maven】聚合和继承
- Maven聚合与继承
- Maven入门-5.Maven的聚合和继承
- maven依赖,聚合和继承
- Maven聚合与继承
- maven的聚合与继承
- Maven之——聚合与继承
- maven 父子项目 聚合与继承 生命周期 打包插件 依赖打包 jar pom war
- Maven学习总结(五)——聚合与继承
- 第七节:Maven中的聚合与继承