maven打包時候修改包名稱帶上git版本號和打包時間方式
更新時間:2023年04月06日 15:18:16 作者:請叫我大師兄_
這篇文章主要介紹了maven打包時候修改包名稱帶上git版本號和打包時間方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
maven打包時候修改包名稱帶上git版本號和打包時間
使用 maven 插件 git-commit-id-plugin 可以獲取項目的git信息,然后,使用這個信息,修改打包的名稱,使其帶上git版本號以及打包時間。
<build> <finalName>${artifactId}-${git.commit.id.abbrev}-${git.build.time}</finalName> <plugins> <plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> <version>2.1.5</version> <executions> <execution> <id>get-the-git-infos</id> <!-- 默認綁定階段initialize --> <phase>initialize</phase> <goals> <goal>revision</goal> </goals> </execution> </executions> <configuration> <!--日期格式;默認值:dd.MM.yyyy '@' HH:mm:ss z;--> <dateFormat>yyyy-MM-dd_HH-mm-ss</dateFormat> <!--,構建過程中,是否打印詳細信息;默認值:false;--> <verbose>true</verbose> <!-- ".git"文件路徑;默認值:${project.basedir}/.git; ${project.basedir}:項目根目錄,即包含pom.xml文件的目錄--> <dotGitDirectory>${project.basedir}/../../../.git</dotGitDirectory> <!--若項目打包類型為pom,是否取消構建;默認值:true;--> <skipPoms>false</skipPoms> <!--是否生成"git.properties"文件;默認值:false;--> <generateGitPropertiesFile>true</generateGitPropertiesFile> <!--指定"git.properties"文件的存放路徑(相對于${project.basedir}的一個路徑);--> <generateGitPropertiesFilename>/src/main/resources/git.properties</generateGitPropertiesFilename> <!--".git"文件夾未找到時,構建是否失敗;若設置true,則構建失敗;若設置false,則跳過執(zhí)行該目標;默認值:true;--> <failOnNoGitDirectory>true</failOnNoGitDirectory> <!--git描述配置,可選;由JGit提供實現(xiàn);--> <gitDescribe> <!--是否生成描述屬性--> <skip>false</skip> <!--提交操作未發(fā)現(xiàn)tag時,僅打印提交操作ID,--> <always>false</always> <!--提交操作ID顯式字符長度,最大值為:40;默認值:7; 0代表特殊意義;后面有解釋;--> <abbrev>7</abbrev> <!--構建觸發(fā)時,代碼有修改時(即"dirty state"),添加指定后綴;默認值:"";--> <dirty>-dirty</dirty> <!--always print using the "tag-commits_from_tag-g_commit_id-maybe_dirty" format, even if "on" a tag. The distance will always be 0 if you're "on" the tag. --> <forceLongFormat>false</forceLongFormat> </gitDescribe> </configuration> </plugin> </plugins> </build>
實際運行結果:
git.properties文件內容
#Generated by Git-Commit-Id-Plugin #Fri Nov 12 15:06:14 CST 2021 git.commit.id.abbrev=ff60f80 git.commit.user.email=xxx@163.com git.commit.message.full=git提交說明 git.commit.id=ff60f8091627e53891fc15bdccad93115f8623c9 git.commit.message.short=簡要說明 git.commit.user.name=abc git.build.user.name=efg git.commit.id.describe=xxxx git.build.user.email=xxx@163.com git.branch=xxx-dev git.commit.time=2011-11-09_14-00-40 git.build.time=2011-11-12_15-06-14 git.remote.origin.url=http\://1.1.1.1\:1/group/xxx.git
maven打包日??偨Y
1、 將第三方依賴性jar包中的文件打包入jar中,打包時修改引入jar包的包名,防止包沖突
?<!--將第三方依賴性jar包中的文件打包入jar中--> ? ? ? ? ? ? <plugin> ? ? ? ? ? ? ? ? <groupId>org.apache.maven.plugins</groupId> ? ? ? ? ? ? ? ? <artifactId>maven-shade-plugin</artifactId> ? ? ? ? ? ? ? ? <!-- 打包失敗可能是版本太低,提高版本 --> ? ? ? ? ? ? ? ? <version>3.1.0</version> ? ? ? ? ? ? ? ? <executions> ? ? ? ? ? ? ? ? ? ? <execution> ? ? ? ? ? ? ? ? ? ? ? ? <phase>package</phase> ? ? ? ? ? ? ? ? ? ? ? ? <goals> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <goal>shade</goal> ? ? ? ? ? ? ? ? ? ? ? ? </goals> ? ? ? ? ? ? ? ? ? ? ? ? <configuration> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <!-- 打包時修改引入jar包的包名,防止包沖突 --> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <relocations> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <relocation> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <pattern>org.apache.http</pattern> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <shadedPattern>shaded.org.apache.http</shadedPattern> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <!--<excludes>--> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <!--<exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>--> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <!--<exclude>org.codehaus.plexus.util.xml.pull.*</exclude>--> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <!--</excludes>--> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </relocation> ? ? ? ? ? ? ? ? ? ? ? ? ? ? </relocations> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <filters> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <filter> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <artifact>*:*</artifact> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <excludes> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <exclude>META-INF/*.SF</exclude> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <exclude>META-INF/*.DSA</exclude> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <exclude>META-INF/*.RSA</exclude> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </excludes> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </filter> ? ? ? ? ? ? ? ? ? ? ? ? ? ? </filters> ? ? ? ? ? ? ? ? ? ? ? ? </configuration> ? ? ? ? ? ? ? ? ? ? </execution> ? ? ? ? ? ? ? ? </executions> ? ? ? ? ? ? </plugin>
2、阻止第三方jar包被打入執(zhí)行包
? ? ? ? <dependency> ? ? ? ? ? ? <groupId>org.apache.hadoop</groupId> ? ? ? ? ? ? <artifactId>hadoop-client</artifactId> ? ? ? ? ? ? <version>2.7.2</version> ? ? ? ? ? ? <!-- 阻止第三方jar包被打入執(zhí)行包 --> ? ? ? ? ? ? <scope>provided</scope> ? ? ? ? </dependency>
3、打包時不包含該包下的部分子包
? ? ? ?<dependency> ? ? ? ? ? ? <groupId>org.elasticsearch.client</groupId> ? ? ? ? ? ? <artifactId>elasticsearch-rest-high-level-client</artifactId> ? ? ? ? ? ? <version>6.3.2</version> ? ? ? ? ? ? <!-- 不包含org.apache.httpcomponents包 --> ? ? ? ? ? ? <exclusions> ? ? ? ? ? ? ? ? <exclusion> ? ? ? ? ? ? ? ? <groupId>org.apache.httpcomponents</groupId> ? ? ? ? ? ? ? ? <artifactId>httpcore</artifactId> ? ? ? ? ? ? ? ? </exclusion> ? ? ? ? ? ? </exclusions> ? ? ? ? </dependency>
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Springboot自帶定時任務實現(xiàn)動態(tài)配置Cron參數(shù)方式
這篇文章主要介紹了Springboot自帶定時任務實現(xiàn)動態(tài)配置Cron參數(shù)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11Java中的Map接口實現(xiàn)類HashMap和LinkedHashMap詳解
這篇文章主要介紹了Java中的Map接口實現(xiàn)類HashMap和LinkedHashMap詳解,我們常會看到這樣的一種集合,IP地址與主機名,等,這種一一對應的關系,就叫做映射,Java提供了專門的集合類用來存放這種對象關系的對象,需要的朋友可以參考下2024-01-01詳解Java對象序列化為什么要使用SerialversionUID
這篇文章主要介紹了詳解Java對象序列化為什么要使用SerialversionUID,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-11-11