日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【maven插件】flatten-maven-plugin : 处理版本占位符

發布時間:2024/9/19 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【maven插件】flatten-maven-plugin : 处理版本占位符 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

  • Apache Maven 3.5.0
  • org.codehaus.mojo:versions-maven-plugin 1.1.0
  • https://www.mojohaus.org/flatten-maven-plugin/

版本占位符

自 Maven 3.5.0-beta-1 開始,可以使用 ${revision}, ${sha1} and/or ${changelist} 這樣的變量作為版本占位符。

像這樣:

<project><modelVersion>4.0.0</modelVersion><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><name>First CI Friendly</name><version>${revision}</version><properties><revision>1.0</revision></properties>... </project>

或者像這樣:

<project><modelVersion>4.0.0</modelVersion><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><name>First CI Friendly</name><version>${revision}${sha1}${changelist}</version>...<properties><revision>1.0</revision><changelist>-SNAPSHOT</changelist><sha1/></properties> </project>

可以使用這樣的命令

mvn -Drevision=2.7.8 -Dchangelist=-RELEASE -Dsha1=ssbd clean package

缺點來了

Install / Deploy 時,版本占位符將不能被替換。這將導致 Install / Deploy 后, maven 不能識別。
使用 flatten-maven-plugin 解決這個問題。

flatten-maven-plugin

<project><modelVersion>4.0.0</modelVersion><groupId>org.apache.maven.ci</groupId><artifactId>ci-parent</artifactId><name>First CI Friendly</name><version>${revision}</version>...<properties><revision>1.0.0-SNAPSHOT</revision></properties><build><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>flatten-maven-plugin</artifactId><version>1.1.0</version><configuration><updatePomFile>true</updatePomFile><flattenMode>oss</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><modules><module>child1</module>..</modules> </project>

eclipse 中提示 lifecycle 錯誤

嗯, eclipse 中會提示 lifecycle 錯誤,需要添加 lifecycle 。

<?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">...<build>...<pluginManagement><plugins><plugin><groupId>org.eclipse.m2e</groupId><artifactId>lifecycle-mapping</artifactId><version>1.0.0</version><inherited>true</inherited><configuration><lifecycleMappingMetadata><pluginExecutions><pluginExecution><pluginExecutionFilter><groupId>org.codehaus.mojo</groupId><artifactId>flatten-maven-plugin</artifactId><versionRange>[1.0.0,)</versionRange><goals><goal>flatten</goal></goals></pluginExecutionFilter><action><ignore /></action></pluginExecution></pluginExecutions></lifecycleMappingMetadata></configuration></plugin></plugins></pluginManagement></build> </project>

參考

https://my.oschina.net/liyuj/blog/874929
https://www.cnblogs.com/jonath/p/7729903.html

總結

以上是生活随笔為你收集整理的【maven插件】flatten-maven-plugin : 处理版本占位符的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。