这篇文章主要介绍了flatten-maven-plugin使用,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
−
将pom工程父子pom的版本,提出作为变量定义在properties。
这样仅修改变量的值(如在运行mvn命令时指定) 即可实现版本整体切换。
删除flatten插件生成的 .flattened-pom.xml
配置参数有:
flattenedPomFilename: 插件生成的pom的名字,默认为
.flattened-pom.xml
outputDirectory:插件生成pom的目录,默认为 ${project.basedir}
在resources-process
生成 .flattened-pom.xml
,并在install/deploy时替换原始pom.xml
主要配置参数有:
flattenedPomFilename: 插件生成的pom的名字,默认为
.flattened-pom.xml
outputDirectory:插件生成pom的目录,默认为 ${project.basedir}
updatePomFile: packing=pom的module也进行reversion变量替换,默认为false
flattenMode:用来定义生成
.flattened-pom.xml
所包含的元素,常用值有:oss:开源软件常用,除了repositories/pluginRepositories外其他所有FlattenDescriptor定义的元素都生成
ossrh:所有FlattenDescriptor定义的元素都生成
bom:在ossrh基础上增加dependencyManagement和properties
defaults:除了repositories其他所有FlattenDescriptor定义的元素都不生成
clean:所有FlattenDescriptor定义的元素都不生成
fatjar:所有FlattenDescriptor定义的元素和dependencies都不生成
resolveCiFriendliesOnly:只替换原始pom中的revision, sha1 and changelist,其他否保持原样
常用oss/ossrh/resolveCiFriendliesOnly
modelVersion
groupId
artifactId
version
packaging
licenses
dependencies
profiles
name
description
url
inceptionYear
organization
scm
developers
contributors
mailingLists
pluginRepositories
issueManagement
ciManagement
distributionManagement
prerequisites
repositories
parent
build
dependencyManagement
properties
modules
reporting
1.父pom定义版本为变量reversion并作为version,子pom复引用变量reversion作为version
2.结果能正常运行compile/test, 但install或deploy时父子pom中的version还是reversion变量未被替换
3.没有version别人无法引用你的包
父pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
子pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
install/deploy后父子pom.xml中的${reversion1}没有被替换
1.父pom定义版本为变量reversion并作为version,子pom复引用变量reversion作为version
2.使用flatten-maven-plugin并设置updatePomFile=true,并绑定goal到maven周期
3.在process-resources阶段时会在父子project目录下生成.flattened-pom.xml(version已替换为具体值)
4.运行install或deploy时会将.flattened-pom.xml替换原来的pom.xml
原始父pom
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|