maven打包時(shí)候修改包名稱帶上git版本號(hào)和打包時(shí)間方式
maven打包時(shí)候修改包名稱帶上git版本號(hào)和打包時(shí)間
使用 maven 插件 git-commit-id-plugin 可以獲取項(xiàng)目的git信息,然后,使用這個(gè)信息,修改打包的名稱,使其帶上git版本號(hào)以及打包時(shí)間。
<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> <!-- 默認(rèn)綁定階段initialize --> <phase>initialize</phase> <goals> <goal>revision</goal> </goals> </execution> </executions> <configuration> <!--日期格式;默認(rèn)值:dd.MM.yyyy '@' HH:mm:ss z;--> <dateFormat>yyyy-MM-dd_HH-mm-ss</dateFormat> <!--,構(gòu)建過程中,是否打印詳細(xì)信息;默認(rèn)值:false;--> <verbose>true</verbose> <!-- ".git"文件路徑;默認(rèn)值:${project.basedir}/.git; ${project.basedir}:項(xiàng)目根目錄,即包含pom.xml文件的目錄--> <dotGitDirectory>${project.basedir}/../../../.git</dotGitDirectory> <!--若項(xiàng)目打包類型為pom,是否取消構(gòu)建;默認(rèn)值:true;--> <skipPoms>false</skipPoms> <!--是否生成"git.properties"文件;默認(rèn)值:false;--> <generateGitPropertiesFile>true</generateGitPropertiesFile> <!--指定"git.properties"文件的存放路徑(相對于${project.basedir}的一個(gè)路徑);--> <generateGitPropertiesFilename>/src/main/resources/git.properties</generateGitPropertiesFilename> <!--".git"文件夾未找到時(shí),構(gòu)建是否失敗;若設(shè)置true,則構(gòu)建失敗;若設(shè)置false,則跳過執(zhí)行該目標(biāo);默認(rèn)值:true;--> <failOnNoGitDirectory>true</failOnNoGitDirectory> <!--git描述配置,可選;由JGit提供實(shí)現(xiàn);--> <gitDescribe> <!--是否生成描述屬性--> <skip>false</skip> <!--提交操作未發(fā)現(xiàn)tag時(shí),僅打印提交操作ID,--> <always>false</always> <!--提交操作ID顯式字符長度,最大值為:40;默認(rèn)值:7; 0代表特殊意義;后面有解釋;--> <abbrev>7</abbrev> <!--構(gòu)建觸發(fā)時(shí),代碼有修改時(shí)(即"dirty state"),添加指定后綴;默認(rèn)值:"";--> <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>
實(shí)際運(yùn)行結(jié)果:
git.properties文件內(nèi)容
#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打包日常總結(jié)
1、 將第三方依賴性jar包中的文件打包入jar中,打包時(shí)修改引入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> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <!-- 打包時(shí)修改引入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、阻止第三方j(luò)ar包被打入執(zhí)行包
? ? ? ? <dependency> ? ? ? ? ? ? <groupId>org.apache.hadoop</groupId> ? ? ? ? ? ? <artifactId>hadoop-client</artifactId> ? ? ? ? ? ? <version>2.7.2</version> ? ? ? ? ? ? <!-- 阻止第三方j(luò)ar包被打入執(zhí)行包 --> ? ? ? ? ? ? <scope>provided</scope> ? ? ? ? </dependency>
3、打包時(shí)不包含該包下的部分子包
? ? ? ?<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>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Springboot自帶定時(shí)任務(wù)實(shí)現(xiàn)動(dòng)態(tài)配置Cron參數(shù)方式
這篇文章主要介紹了Springboot自帶定時(shí)任務(wù)實(shí)現(xiàn)動(dòng)態(tài)配置Cron參數(shù)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11springCloud集成nacos啟動(dòng)時(shí)報(bào)錯(cuò)原因排查
這篇文章主要介紹了springCloud集成nacos啟動(dòng)時(shí)報(bào)錯(cuò)原因排查,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04Java中的Map接口實(shí)現(xiàn)類HashMap和LinkedHashMap詳解
這篇文章主要介紹了Java中的Map接口實(shí)現(xiàn)類HashMap和LinkedHashMap詳解,我們常會(huì)看到這樣的一種集合,IP地址與主機(jī)名,等,這種一一對應(yīng)的關(guān)系,就叫做映射,Java提供了專門的集合類用來存放這種對象關(guān)系的對象,需要的朋友可以參考下2024-01-01詳解Java對象序列化為什么要使用SerialversionUID
這篇文章主要介紹了詳解Java對象序列化為什么要使用SerialversionUID,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11微信企業(yè)號(hào) 根據(jù)錯(cuò)誤碼返回錯(cuò)誤信息類封裝
這篇文章主要介紹了微信企業(yè)號(hào) 根據(jù)錯(cuò)誤碼返回錯(cuò)誤信息類封裝的相關(guān)資料,需要的朋友可以參考下2016-10-10