【maven插件】flatten-maven-plugin : 处理版本占位符
生活随笔
收集整理的這篇文章主要介紹了
【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 : 处理版本占位符的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 交大emba怎么样(交大安泰emba学费
- 下一篇: 查看进程状态信息命令 jps - (Ja