flatten-maven-plugin使用教程
一、簡介
1.1 作用
將pom工程父子pom的版本,提出作為變量定義在properties。
這樣僅修改變量的值(如在運(yùn)行mvn命令時(shí)指定) 即可實(shí)現(xiàn)版本整體切換。
1.2 goal介紹
- flatten:clean
刪除flatten插件生成的 .flattened-pom.xml
配置參數(shù)有:
flattenedPomFilename: 插件生成的pom的名字,默認(rèn)為
.flattened-pom.xml
outputDirectory:插件生成pom的目錄,默認(rèn)為 ${project.basedir}
- flatten:flatten
在resources-process
生成 .flattened-pom.xml
,并在install/deploy時(shí)替換原始pom.xml
主要配置參數(shù)有:
flattenedPomFilename: 插件生成的pom的名字,默認(rèn)為
.flattened-pom.xml
outputDirectory:插件生成pom的目錄,默認(rèn)為 ${project.basedir}
updatePomFile: packing=pom的module也進(jìn)行reversion變量替換,默認(rèn)為false
flattenMode:用來定義生成
.flattened-pom.xml
所包含的元素,常用值有:oss:開源軟件常用,除了repositories/pluginRepositories外其他所有FlattenDescriptor定義的元素都生成
ossrh:所有FlattenDescriptor定義的元素都生成
bom:在ossrh基礎(chǔ)上增加dependencyManagement和properties
defaults:除了repositories其他所有FlattenDescriptor定義的元素都不生成
clean:所有FlattenDescriptor定義的元素都不生成
fatjar:所有FlattenDescriptor定義的元素和dependencies都不生成
resolveCiFriendliesOnly:只替換原始pom中的revision, sha1 and changelist,其他否保持原樣
常用oss/ossrh/resolveCiFriendliesOnly
- FlattenDescriptor定義的pom.xml元素有:
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
二、使用總結(jié)
- 不用flatten-maven-plugin
1.父pom定義版本為變量reversion并作為version,子pom復(fù)引用變量reversion作為version
2.結(jié)果能正常運(yùn)行compile/test, 但install或deploy時(shí)父子pom中的version還是reversion變量未被替換
3.沒有version別人無法引用你的包
父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> <packaging>pom</packaging> <version>${reversion1}</version> <modules> <module>no-flatten-child</module> </modules> <groupId>com.wsl.my.maven</groupId> <artifactId>no-flatten-plugin</artifactId> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <reversion1>1.1.0-SNAPSHOT</reversion1> </properties> </project>
子pom.xml
<?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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>no-flatten-plugin</artifactId> <groupId>com.wsl.my.maven</groupId> <version>${reversion1}</version> <relativePath>../pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>no-flatten-child</artifactId> </project>
install/deploy后父子pom.xml中的${reversion1}沒有被替換
- 使用了flatten-maven-plugin
1.父pom定義版本為變量reversion并作為version,子pom復(fù)引用變量reversion作為version
2.使用flatten-maven-plugin并設(shè)置updatePomFile=true,并綁定goal到maven周期
3.在process-resources階段時(shí)會(huì)在父子project目錄下生成.flattened-pom.xml(version已替換為具體值)
4.運(yùn)行install或deploy時(shí)會(huì)將.flattened-pom.xml替換原來的pom.xml
原始父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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <version>${reversion2}</version> <packaging>pom</packaging> <artifactId>use-flatten-parent</artifactId> <groupId>com.wsl.my.maven</groupId> <modules> <module>use-flatten-child</module> </modules> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <reversion2>1.2.0-SNAPSHOT</reversion2> </properties> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>flatten-maven-plugin</artifactId> <version>1.2.7</version> <configuration> <updatePomFile>true</updatePomFile> <flattenMode>resolveCiFriendliesOnly</flattenMode> </configuration> <executions> <execution> <id>flatten</id> <phase>process-resources</phase> <goals> <goal>flatten</goal> </goals> </execution> <execution> <id>flatten-clean</id> <phase>clean</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
到此這篇關(guān)于flatten-maven-plugin使用的文章就介紹到這了,更多相關(guān)flatten-maven-plugin使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java實(shí)現(xiàn)文件監(jiān)控器FileMonitor的實(shí)例代碼
這篇文章主要介紹了Java實(shí)現(xiàn)文件監(jiān)控器FileMonitor的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12SpringBoot使用Spring-Data-Jpa實(shí)現(xiàn)CRUD操作
這篇文章主要為大家詳細(xì)介紹了SpringBoot使用Spring-Data-Jpa實(shí)現(xiàn)CRUD操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08Java如何獲取resources下的文件路徑和創(chuàng)建臨時(shí)文件
這篇文章主要介紹了Java如何獲取resources下的文件路徑和創(chuàng)建臨時(shí)文件,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12Spring注解驅(qū)動(dòng)之關(guān)于@Bean注解指定初始化和銷毀的方法
這篇文章主要介紹了Spring注解驅(qū)動(dòng)之關(guān)于@Bean注解指定初始化和銷毀的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09SpringBoot整合Drools規(guī)則引擎動(dòng)態(tài)生成業(yè)務(wù)規(guī)則的實(shí)現(xiàn)
本文主要介紹了SpringBoot整合Drools規(guī)則引擎動(dòng)態(tài)生成業(yè)務(wù)規(guī)則的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12springboot 如何通過SpringTemplateEngine渲染html
通過Spring的Thymeleaf模板引擎可以實(shí)現(xiàn)將模板渲染為HTML字符串,而不是直接輸出到瀏覽器,這樣可以對(duì)渲染后的字符串進(jìn)行其他操作,如保存到文件或進(jìn)一步處理,感興趣的朋友跟隨小編一起看看吧2024-10-10Java 讀取網(wǎng)絡(luò)圖片存儲(chǔ)到本地并生成縮略圖
用Java做開發(fā)經(jīng)常需要處理圖片。本文就來看一下如何保存圖片到本地并生成縮略圖2021-05-05