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)建過(guò)程中,是否打印詳細(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"文件的存放路徑(相對(duì)于${project.basedir}的一個(gè)路徑);-->
<generateGitPropertiesFilename>/src/main/resources/git.properties</generateGitPropertiesFilename>
<!--".git"文件夾未找到時(shí),構(gòu)建是否失敗;若設(shè)置true,則構(gòu)建失敗;若設(shè)置false,則跳過(guò)執(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顯式字符長(zhǎng)度,最大值為: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提交說(shuō)明 git.commit.id=ff60f8091627e53891fc15bdccad93115f8623c9 git.commit.message.short=簡(jiǎn)要說(shuō)明 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(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)文章
postman中POST請(qǐng)求時(shí)參數(shù)包含參數(shù)list設(shè)置方式
這篇文章主要介紹了postman中POST請(qǐng)求時(shí)參數(shù)包含參數(shù)list設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05
jackson使用@JsonSerialize格式化BigDecimal解決.00不顯示問(wèn)題
這篇文章主要介紹了jackson使用@JsonSerialize格式化BigDecimal解決.00不顯示問(wèn)題,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-02-02

