Maven继承

父pom配置:

<packaging>pom</packaging>

在父pom中配置依赖管理和插件管理

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>cxxcode.maven</groupId>

<artifactId>account-parent</artifactId>

<packaging>pom</packaging>

<version>0.0.1</version>

<name>Account Parent</name>

<url>http://maven.apache.org</url>

<properties>

<spring-version>2.5.6</spring-version>

<junit-version>4.7</junit-version>

<mail-version>1.4.1</mail-version>

<greenmail-version>1.3.1b</greenmail-version>

<dom4j-version>1.6.1</dom4j-version>

<surefire-version>2.5</surefire-version>

</properties>

<!--

依赖管理dependencyManagement

假设不使用依赖管理。子pom会继承父pom中配置的全部依赖,子pom中仅仅需配置自己特需的依赖即可了,

这样尽管简化了子pom的配置。可是强制性给子pom加上多余的依赖。

使用依赖管理,子pom中要配置自己须要的依赖。假设这些依赖在父pom中配置了,

子pom仅仅需指定这些依赖的groupId和artifactId

依赖管理的导入

将proj-A中的依赖管理导入此pom的依赖管理中

<scope>import</scope>仅仅用在依赖管理配置中。且<type>pom</type>

<dependencyManagement>

<dependencies>

<dependency>

<groupId>cxxcode.mave</groupId>

<artifactId>proj-A</artifactId>

<version>0.0.1</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>

-->

<dependencyManagement>

<dependencies>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

<version>${spring-version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-beans</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-context-support</artifactId>

<version>${spring-version}</version>

</dependency>

<dependency>

<groupId>javax.mail</groupId>

<artifactId>mail</artifactId>

<version>${mail-version}</version>

</dependency>

<dependency>

<groupId>dom4j</groupId>

<artifactId>dom4j</artifactId>

<version>${dom4j-version}</version>

</dependency>

<dependency>

<groupId>com.icegreen</groupId>

<artifactId>greenmail</artifactId>

<version>${greenmail-version}</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>${junit-version}</version>

<scope>test</scope>

</dependency>

</dependencies>

</dependencyManagement>

<build>

<!-- 插件管理pluginManagement -->

<pluginManagement>

<plugins>

<!-- 编译插件 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.5</source>

<target>1.5</target>

<fork>true</fork><!-- true同意改动jdk编码版本号 -->

<encoding>UTF-8</encoding>

<!-- 跳过測试编译

<skip>false</skip> -->

</configuration>

</plugin>

<!-- 生成源代码jar -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-source-plugin</artifactId>

<executions>

<execution>

<phase>verify</phase>

<goals>

<goal>jar-no-fork</goal>

</goals>

</execution>

</executions>

</plugin>

<!-- 复制主资源文件到主输出文件夹 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<configuration>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<!-- 測试插件 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-surefire-plugin</artifactId>

<version>${surefire-version}</version>

<configuration>

<!-- 跳过測试

<skip>true</skip> -->

</configuration>

</plugin>

</plugins>

</pluginManagement>

</build>

</project>

==================================

子pom

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<!-- 独自己定义

<groupId>cxxcode.maven</groupId>

<artifactId>account-email</artifactId>

<packaging>jar</packaging>

<version>0.0.1</version>

<name>Account Email</name>

-->

<!--

parent

继承父pom

子pom的groupId、version、依赖等信息继承父pom

relativePath 父pom的位置。默认../pom.xml

可继承的pom元素

groupId   项目组Id

version   项目版本号

description  项目描写叙述

organization 项目的组织信息

inceptionYear 项目的创建年份

url    项目的url

developers  项目的开发人员

contributors 项目的贡献者

distributionManagement 项目的部署配置

issueManagement 项目的缺陷跟踪系统信息

ciManagement 项目的持续继承系统信息

scm    项目的版本号控制系统信息

mailingLists 项目的邮件列表信息

properties  自己定义的maven属性

dependencies 项目的依赖配置

dependencyManagement 项目的依赖管理配置

repositories 项目的仓库配置

build   包含项目的源代码文件夹配置,输出文件夹配置、插件配置、插件管理配置等

reporting  包含项目的报告输出文件夹配置、报告插件配置等

-->

<artifactId>account-email</artifactId>

<packaging>jar</packaging>

<name>Account Email</name>

<parent>

<groupId>cxxcode.maven</groupId>

<artifactId>account-parent</artifactId>

<version>0.0.1</version>

<relativePath>../CXXMaven_AccountParent/pom.xml</relativePath>

</parent>

<dependencies>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-beans</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context-support</artifactId>

</dependency>

<dependency>

<groupId>javax.mail</groupId>

<artifactId>mail</artifactId>

</dependency>

<dependency>

<groupId>com.icegreen</groupId>

<artifactId>greenmail</artifactId>

<scope>test</scope>

</dependency>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

</dependency>

</dependencies>

<build>

<plugins>

<!-- 编译插件 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

</plugin>

<!-- 生成可执行的jar -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-shade-plugin</artifactId>

<executions>

<execution>

<phase>package</phase>

<goals>

<goal>shade</goal>

</goals>

<configuration>

<transformers>

<transformer

implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

<mainClass>

com.cxx.maven.App

</mainClass>

</transformer>

</transformers>

</configuration>

</execution>

</executions>

</plugin>

<!-- 生成源代码jar -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-source-plugin</artifactId>

</plugin>

</plugins>

</build>

</project>

时间: 2024-08-03 06:44:51

Maven继承的相关文章

maven 继承关系和聚合

maven继承管理 让版本的管理只在一个地方改变 modules用于聚合,把执行的项目都放到同一的地方用module包括,可以省去一个个项目去mvn install,这样可以所有项目一次聚合 mvn install 传递性依赖原则: A-->BA-->C 1.路径最近者优先2.路径相同,第一声明者优先 注意:1.dependencyManagement中定义的依赖子module不会共享2.dependencies中定义的依赖子module可以共享 dependencyManagement的使用

MAVEN 继承使用时出错点

父POM: <?xml version="1.0" encoding="UTF-8"?> <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

maven 继承 聚合

Maven聚合与继承 一.聚合 为了能够使用一条命令就能构建 account-email和 account-persist两个模块,我们需要建立一个额外的名为 account-aggregator的模块,然后通过该模块构建整个项目的所有模块. account-aggregator本身也是个 Maven项目,它的 POM如下 Xml代码   <project> <modelVersion>4.0.0</modelVersion> <groupId>com.ju

maven in action(五)maven继承和聚合

问题的提出: 当一个项目依赖多个其他项目或者模块的时候,可以A模块引用了junit jar,B模块也引用了junit jar,而这个项目依赖于A.B模块,这样就没有必要重复添加junit jar坐标依赖.这时候,我们可以单独的一个项目来管理jar的坐标依赖,也就是下面要说的依赖的继承. 继承 面向对象思想中有继承,子类继承父类不是私有的方法和属性. 在maven中的继承,我们可以抽取出所有公共的jar坐标,然后建立一个parent的项目,该项目中仅包含有一个pom.xml文件,并且parent项

Maven快速使用教程(六) Maven继承和聚合

maven聚合和继承

011.maven 继承与聚合

聚合:对于聚合模块来说,它知道有哪些被聚合的模块,而对于被聚合的模块来说,它们不知道被谁聚合了,也不知道它的存在: 继承:对于继承关系的父POM来说,它不知道自己被哪些子模块继承了,对于子POM来说,它必须知道自己的父POM是谁: 在一些最佳实践中我们会发现:一个POM既是聚合POM,又是父POM,这么做主要是为了方便. 链接:https://www.cnblogs.com/sxpy-lj/p/7251418.html 一.继承 为了避免重复.通过继承拥有Parent项目中的配置. https:

maven继承父工程统一版本号

一.建立一个maven工程 pom类型 统一管理依赖以及版本号 子工程不会使用所有的定义的依赖 子工程使用依赖时无需指定版本号 其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

Maven聚合模块与继承和Maven的生命周期

端碗吹水 Maven聚合模块: 因为Maven是提倡模块化编程的,所以会以多个工程分为多个模块.如果所有的功能.模块都写在一个工程里的话,不方便于扩展.升级.修改.查看和团队开发,而且也不方便于模块的复用. Maven则是提倡将一个项目拆分成多个工程,每个工程完成一个模块或功能,这些工程就像零件一般,分别去进行开发,分为多个工程也方便于维护和分工合作. 每个工程模块可以通过pom配置文件实现串联,例如配置好pom文件之后,A工程可以直接对B工程的代码进行调用,C工程可以对A和B工程的代码进行调用

Java-Maven(七):Eclipse中Maven依赖、聚合、继承特性

之前通过学习了解,maven集成到eclipse中的如何创建项目,以及maven命令插件在eclipse中安装后的用法.那么接下来我们将会学习一些maven在项目中的一些特性,及如何使用. Maven依赖特性 Maven聚合特性 Maven继承特性