Maven的pom.xml文件详解------Build Settings

转载自  Maven的pom.xml文件详解------Build Settings

根据POM 4.0.0 XSD,build元素概念性的划分为两个部分:BaseBuild(包含poject build和profile build的公共部分,见下)和poject build包含的一些高级特性。 

<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">...<!-- "Project Build" contains more elements than just the BaseBuild set --><build>...</build><profiles><profile><!-- "Profile Build" contains a subset of "Project Build"s elements --><build>...</build></profile></profiles>
</project>

 

BaseBuild元素集合

basic elements

<build><defaultGoal>install</defaultGoal><directory>${basedir}/target</directory><finalName>${artifactId}-${version}</finalName><filters><filter>filters/filter1.properties</filter></filters>...
</build>

1、defaultGoal:执行build任务时,如果没有指定目标,将使用的默认值,如:在命令行中执行mvn,则相当于执行mvn install; 
2、directory:build目标文件的存放目录,默认在${basedir}/target目录; 
3、finalName:build目标文件的文件名,默认情况下为${artifactId}-${version}; 
4、filter:定义*.properties文件,包含一个properties列表,该列表会应用的支持filter的resources中。也就是说,定义在filter的文件中的"name=value"值对会在build时代替${name}值应用到resources中。Maven的默认filter文件夹是${basedir}/src/main/filters/。

 

resources

build的另一个特征是指定你的项目中resources的位置。resources(通常)不是代码,他们不被编译,但是被绑定在你的项目或者用于其它什么原因,例如代码生成。

<build>...<resources><resource><targetPath>META-INF/plexus</targetPath><filtering>false</filtering><directory>${basedir}/src/main/plexus</directory><includes><include>configuration.xml</include></includes><excludes><exclude>**/*.properties</exclude></excludes></resource></resources><testResources>...</testResources>...
</build>

1、resources:一个resource元素的列表,每一个都描述与项目关联的文件是什么和在哪里; 
2、targetPath:指定build后的resource存放的文件夹。该路径默认是basedir。通常被打包在JAR中的resources的目标路径为META-INF; 
3、filtering:true/false,表示为这个resource,filter是否激活。 
4、directory:定义resource所在的文件夹,默认为${basedir}/src/main/resources; 
5、includes:指定作为resource的文件的匹配模式,用*作为通配符; 
6、excludes:指定哪些文件被忽略,如果一个文件同时符合includes和excludes,则excludes生效; 
7、testResources:定义和resource类似,但只在test时使用,默认的test resource文件夹路径是${basedir}/src/test/resources,test resource不被部署。 

 

Plugins

<build>...<plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>2.0</version><extensions>false</extensions><inherited>true</inherited><configuration><classifier>test</classifier></configuration><dependencies>...</dependencies><executions>...</executions></plugin></plugins>
</build>

 除了groupId:artifactId:version标准坐标,plugin还需要如下属性: 
1、extensions:true/false,是否加载plugin的extensions,默认为false; 
2、inherited:true/false,这个plugin是否应用到该POM的孩子POM,默认true; 
3、configuration:配置该plugin期望得到的properies,如上面的例子,我们为maven-jar-plugin的Mojo设置了classifier属性; 

如果你的POM有一个parent,它可以从parent的build/plugins或者pluginManagement集成plugin配置。

为了阐述继承后的关系,考虑如果parent POM中存在如下plugin:

<plugin><groupId>my.group</groupId><artifactId>my-plugin</artifactId><configuration><items><item>parent-1</item><item>parent-2</item></items><properties><parentKey>parent</parentKey></properties></configuration>
</plugin>

 然后在继承的孩子POM中做如下配置:

<plugin><groupId>my.group</groupId><artifactId>my-plugin</artifactId><configuration><items><item>child-1</item></items><properties><childKey>child</childKey></properties></configuration>
</plugin>

这样孩子POM和parent POM中都存在groupId为my.group的plugin,Maven默认的行为将是根据属性名称将两个plugin的configuration的内容进行合并。如果孩子POM中有一个属性,则该属性是有效的,如果孩子POM中没有一个属性,但parent POM中存在,则parent中的属性是有效的。

根据这些规则,上面的例子在Maven中将得到:

<plugin><groupId>my.group</groupId><artifactId>my-plugin</artifactId><configuration><items><item>child-1</item></items><properties><childKey>child</childKey><parentKey>parent</parentKey></properties></configuration>
</plugin>

通过在configuration元素中增加combine.children和combine.self属性,孩子POM可以控制Maven怎么合并plugin的configuration。

假定这儿是孩子POM的configuration:

<configuration><items combine.children="append"><!-- combine.children="merge" is the default --><item>child-1</item></items><properties combine.self="override"><!-- combine.self="merge" is the default --><childKey>child</childKey></properties>
</configuration>

则,现在合并后的效果如下:

<configuration><items combine.children="append"><item>parent-1</item><item>parent-2</item><item>child-1</item></items><properties combine.self="override"><childKey>child</childKey></properties>
</configuration>

combine.children="append"表示父POM和子POM的属性合并起来;

combine.self="override"表示子POM的属性完全覆盖父POM的。

4、dependencies:同base build中的dependencies有同样的结构和功能,但这里是作为plugin的依赖,而不是项目的依赖。
5、executions:plugin可以有多个目标,每一个目标都可以有一个分开的配置,甚至可以绑定一个plugin的目标到一个不同的阶段。executions配置一个plugin的目标的execution。

假定一项绑定antrun:run目标到verify阶段,我们希望任务响应build文件夹,同时避免传递配置到他的孩子POM。你将得到一个execution:

<build><plugins><plugin><artifactId>maven-antrun-plugin</artifactId><version>1.1</version><executions><execution><id>echodir</id><goals><goal>run</goal></goals><phase>verify</phase><inherited>false</inherited><configuration><tasks><echo>Build Dir: ${project.build.directory}</echo></tasks></configuration></execution></executions></plugin></plugins>
</build>

id:标识,用于和其他execution区分。当这个阶段执行时,它将以这个形式展示:[plugin:goal execution: id]。在这里为: [antrun:run execution: echodir];

goals:一个plugin的execution的目标列表;

phase:目标执行的阶段,具体值看Maven的生命周期列表;

inherited:是否继承;

configuration:在指定的目标下的配置。

Plugin Management

pluginManagement的元素的配置和plugins的配置是一样的,只是这里的配置只是用于集成,在孩子POM中指定使用。例如,在父POM中做如下配置:

<build>...<pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>2.2</version><executions><execution><id>pre-process-classes</id><phase>compile</phase><goals><goal>jar</goal></goals><configuration><classifier>pre-process</classifier></configuration></execution></executions></plugin></plugins></pluginManagement>...
</build>

则在孩子POM中,我们只需要配置: 

<build>...<plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId></plugin></plugins>...
</build>

这样就可以大大的简化孩子POM中的配置。 

 

Reporting

Reporting包含的属性对应到site阶段(见Maven生命周期)。特定的Maven插件能产生定义和配置在reporting元素下的报告,例如:产生Javadoc报告。

<reporting><outputDirectory>${basedir}/target/site</outputDirectory><plugins><plugin><artifactId>maven-project-info-reports-plugin</artifactId><version>2.0.1</version><reportSets><reportSet></reportSet></reportSets></plugin></plugins>
</reporting>

对于reportSets: 

<reportSets><reportSet><id>sunlink</id><reports><report>javadoc</report></reports><inherited>true</inherited><configuration><links><link>http://java.sun.com/j2se/1.5.0/docs/api/</link></links></configuration></reportSet>
</reportSets>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/322677.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

git代码合并冲突与撤回提交

查看版本 切回到某一个版本 git log --graph --abbrev-commit --decorate --prettyoneline git reset --hard a07cefe git有一种情况会造成代码被冲掉&#xff1a; 这里有A端和B端&#xff1a; 相同文本基础之上 A端写了大量代码&#xff0c;提交推送 B端拉取&#xff0c;改了代…

Asp.net Core中SignalR Core预览版的一些新特性前瞻,附源码(消息订阅与发送二进制数据)

前言 一晃一个月又过去了,上个月有个比较大的项目要验收上线.所以忙的脚不沾地.现在终于可以忙里偷闲,写一篇关于SignalR Core的文章了. 先介绍一下SignalR吧,如下: ASP.NET SignalR是ASP.NET开发人员的一个库&#xff0c;它简化了向Web应用程序添加即时通讯功能的过程。 它可以…

P3225-[HNOI2012]矿场搭建【tarjan,图论】

正题 题目链接:https://www.luogu.org/problemnew/show/P3225 题目大意 nnn个点的无向图&#xff0c;要求设置逃生点使得任意一个点去掉后每联通分量内都有一个逃生点。求至少多少个逃生点和方案数。 解题思路 首先tarjantarjantarjan求出割点&#xff0c;然后对于一个分量内…

Maven的pom.xml文件详解------Environment Settings

转载自 Maven的pom.xml文件详解------Environment Settings Issue Management 使用的缺陷跟踪系统&#xff08;Bugzilla&#xff0c;TestTrack&#xff0c;ClearQuest&#xff0c;等&#xff09;信息&#xff0c;主要用于产生项目文档。 <issueManagement><system…

大二暑假工作三个月后辞职,总体感悟

本人是个大二的学生&#xff0c;因为疫情影响&#xff0c;学校放了很长时间的假。当时对自己的前端技术很自信&#xff0c;大概在五月底的时候决定去上海闯一下&#xff0c;找个工作&#xff0c;不管能不能找到&#xff0c;就是尝试一下&#xff0c;失败了也没关系&#xff0c;…

P5004-专心OI - 跳房子【dp,矩阵乘法】

正题 题目链接:https://www.luogu.org/problemnew/show/P5004 题目大意 把NNN个无色格子排成一行&#xff0c;可以把某些格子染成黑色&#xff0c;但两个黑色格子之间必须至少有MMM个无色格子&#xff0c;求方案数 解题思路 首先很明显 fn∑i0n−m−1fif_n\sum_{i0}^{n-m-1}…

35年编程史沉淀下来的8条宝贵经

01 1. 时刻提醒自己&#xff1a;学习 学习某件事的第一步是承认你不知道。这听起来很正常&#xff0c;但经验丰富的程序员还记得要真正让自己承认这一点需要花多长时间。很多计算机科学专业的学生毕业的时候&#xff0c;都有一种很傲慢的态度&#xff0c;就是“我知道最好的”&…

Maven的pom.xml文件详解------The Basics

转载自 Maven的pom.xml文件详解------The Basics Maven坐标 GroupId、artifactId和version构成了Maven的坐标&#xff08;groupId和version可以从parent继承&#xff09;&#xff0c;指定了组件在Maven仓库中的位置。Maven中的每个组件都有一个坐标&#xff0c;通过这个坐标…

php artisan快捷命令

远程启动laravel&#xff1a; php artisan serve --host 0.0.0.0 创建新的Controller php artisan make:controller loginController 创建快捷资源Controller php artisan make:controller ArticlesController --resource 对应的创建快捷路由 Route::resource(‘articles’,…

P1407-[国家集训队]稳定婚姻【tarjan,强连通分量】

正题 题目链接:https://www.luogu.org/problemnew/show/P1407 题目大意 若干对夫妻&#xff0c;和若干对绿色关系&#xff0c;求每对夫妻离婚后&#xff0c;绿色关系是否可以重新让每个人两两配对。 解题思路 我们可以让 夫妻女的连男的 交往男的连女的 然后跑tarjantarjan…

基于Emgu CV+百度人脸识别,实现视频动态 人脸抓取与识别

背景 目前AI 处于风口浪尖&#xff0c;作为 公司的CTO&#xff0c;也作为自己的技术专研&#xff0c;开始了AI之旅&#xff0c;在朋友圈中也咨询 一些大牛对于AI 机器学习框架的看法&#xff0c;目前自己的研究方向主要开源的 AI 库&#xff0c;如&#xff1a;Emgu CV、TensorF…

Lombok的@Data生成的hashCode和equals方法坑

一、场景复现 创建两个lombok的Data注解的类Pig实例&#xff0c;放进HashMap当key&#xff0c;map里面的数据居然被覆盖了。 package com.mk;import lombok.Data; Data public class Pig extends Animal{private String sex; }package com.mk;import java.util.HashMap; impo…

vscode多行选中

shiftalt移动光标&#xff0c;可以连续同时编辑多行内容

jzoj4671-World Tour【图论,bfs】

正题 luogu题目链接:https://www.luogu.org/problemnew/show/CF666B 题目大意 求4个点&#xff0c;使得这4个点按顺序最短路到达的长度最远。 解题思路 用bfsbfsbfs求出每个点之间的最短路&#xff0c;然后对于每个点求出最远点&#xff0c;次远点&#xff0c;反最远点和反次…

vue-cli2、vue-cli3脚手架详细讲解

转载自 vue-cli2、vue-cli3脚手架详细讲解 前言&#xff1a; vue脚手架指的是vue-cli它是vue官方提供的一个快速构建单页面&#xff08;SPA&#xff09;环境配置的工具&#xff0c;cli 就是(command-line-interface ) 命令行界面 。vue-cli是基于node环境利用webpack对文件进…

微软为.NET程序员带来了最优的跨平台开发体验-WSL

前言 在前几个Visual Studio Code更新中发现有一个重要得特性&#xff0c;就是nodejs可以使用VS Code在WSL中进行Debug了&#xff08;WSL是指Win10中的Linux子系统&#xff09;,之前写过一篇文章是使用SSH对Linux环境进行Debug&#xff0c;此时的想法就是如果可以在WSL中直接对…

article之api文档

查 method:get http://127.0.0.1:8000/article 单条 http://127.0.0.1:8000/article/10 method:get 新增 http://127.0.0.1:8000/article method:post 修改 http://127.0.0.1:8000/article/10 method:put 删除 http://127.0.0.1:8000/article/3 method:delete ## 查询所有数据&…

jzoj4672-Graph Coloring【图论,模拟】

正题 题目大意 一张无向图&#xff0c;每条边有一个颜色(红或蓝)&#xff0c;可以选择点使得连接的边都取反&#xff0c;求至少要选多个点可以使得所有边的颜色相同。 解题思路 不难发现如果确定所有边的颜色&#xff0c;然后知道一个点的选择后就可以知道整个联通图的选择。…

Redis 性能问题分析

转载自 Redis 性能问题分析 在一些网络服务的系统中&#xff0c;Redis 的性能&#xff0c;可能是比 MySQL 等硬盘数据库的性能更重要的课题。比如微博&#xff0c;把热点微博[1]&#xff0c;最新的用户关系&#xff0c;都存储在 Redis 中&#xff0c;大量的查询击中 Redis&am…

谈谈微服务中的 API 网关(API Gateway)

前言 又是很久没写博客了&#xff0c;最近一段时间换了新工作&#xff0c;比较忙&#xff0c;所以没有抽出来太多的时间写给关注我的粉丝写一些干货了&#xff0c;就有人问我怎么最近没有更新博客了&#xff0c;在这里给大家抱歉。 那么&#xff0c;在本篇文章中&#xff0c;我…