国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot使用git-commit-id-maven-plugin打包

這篇具有很好參考價(jià)值的文章主要介紹了SpringBoot使用git-commit-id-maven-plugin打包。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

簡(jiǎn)介

git-commit-id-maven-plugin 是一個(gè)maven 插件,用來(lái)在打包的時(shí)候?qū)it-commit 信息打進(jìn)jar中。

這樣做的好處是可以將發(fā)布的某版本和對(duì)應(yīng)的代碼關(guān)聯(lián)起來(lái),方便查閱和線上項(xiàng)目的維護(hù)。至于它的作用,用官方說(shuō)法,這個(gè)功能對(duì)于大型分布式項(xiàng)目來(lái)說(shuō)是無(wú)價(jià)的。

功能

你是否經(jīng)常遇到這樣的問(wèn)題:

  • 測(cè)試提交了一個(gè)bug,開(kāi)發(fā)人員無(wú)法確認(rèn)是哪個(gè)版本有這個(gè)問(wèn)題,當(dāng)前測(cè)試環(huán)境部署的是某個(gè)版本嗎?生產(chǎn)環(huán)境會(huì)不會(huì)也有這個(gè)問(wèn)題?

  • 公司內(nèi)部的項(xiàng)目,總共幾十、幾百個(gè)服務(wù),每天都有服務(wù)的生產(chǎn)環(huán)境部署,一個(gè)服務(wù)甚至一天上線好幾次,對(duì)于項(xiàng)目管理來(lái)說(shuō)無(wú)法清晰了解某一時(shí)刻某個(gè)服務(wù)的版本

  • 如何驗(yàn)證我的代碼是否已經(jīng)上線?

  • 。。。。。。

以上種種,都有一個(gè)共同的訴求,就是我希望在打包的時(shí)候?qū)⒆詈笠淮?git commit id 和當(dāng)前 jar 關(guān)聯(lián)起來(lái)并可試試查詢jar對(duì)應(yīng)的git commit id 。

實(shí)踐

引入插件

本例SpringBoot版本為 2.7.6,java版本為11

此插件已經(jīng)上傳到中央倉(cāng)庫(kù)(https://central.sonatype.com/artifact/io.github.git-commit-id/git-commit-id-maven-plugin?smo=true)

在項(xiàng)目pom.xml 中引入如下插件



<project>
? ? ......
? ? <build>
? ? ? ? <plugins>
? ? ? ? ? ? <!-- ?git-commit-id-maven-plugin :打包的時(shí)候攜帶git提交信息 ?-->
? ? ? ? ? ? <plugin>
? ? ? ? ? ? ? ? <groupId>io.github.git-commit-id</groupId>
? ? ? ? ? ? ? ? <artifactId>git-commit-id-maven-plugin</artifactId>
? ? ? ? ? ? ? ? <version>5.0.0</version>
? ? ? ? ? ? ? ? <executions>
? ? ? ? ? ? ? ? ? ? <execution>
? ? ? ? ? ? ? ? ? ? ? ? <id>get-the-git-infos</id>
? ? ? ? ? ? ? ? ? ? ? ? <goals>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <goal>revision</goal>
? ? ? ? ? ? ? ? ? ? ? ? </goals>
? ? ? ? ? ? ? ? ? ? ? ? <phase>initialize</phase>
? ? ? ? ? ? ? ? ? ? </execution>
? ? ? ? ? ? ? ? </executions>
? ? ? ? ? ? ? ? <configuration>
? ? ? ? ? ? ? ? ? ? <generateGitPropertiesFile>true</generateGitPropertiesFile>
? ? ? ? ? ? ? ? ? ? <generateGitPropertiesFilename>${project.build.outputDirectory}/git.</generateGitPropertiesFilename>
? ? ? ? ? ? ? ? ? ? <includeOnlyProperties>
? ? ? ? ? ? ? ? ? ? ? ? <includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
? ? ? ? ? ? ? ? ? ? ? ? <includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
? ? ? ? ? ? ? ? ? ? </includeOnlyProperties>
? ? ? ? ? ? ? ? ? ? <format>txt</format>
? ? ? ? ? ? ? ? ? ? <commitIdGenerationMode>full</commitIdGenerationMode>
? ? ? ? ? ? ? ? </configuration>
? ? ? ? ? ? </plugin>
? ? ? ? </plugins>
? ? </build>
</project>



  • generateGitPropertiesFilename:用于指定生成的gitCommitInfo存放到哪個(gè)位置,后綴可以任意指定,如果不指定將使用format的值
  • format:指定文件后綴,一般為 properties , json
  • commitIdGenerationMode:記錄完整信息,若format為json,此值必須為full

此外為了能成功打出jar包,還需要如下插件的配合:



<plugin>
? ? <groupId>org.springframework.boot</groupId>
? ? <artifactId>spring-boot-maven-plugin</artifactId>
? ? <version>${spring-boot.version}</version>
? ? <configuration>
? ? ? ? <includeSystemScope>true</includeSystemScope>
? ? ? ? <excludes>
? ? ? ? ? ? <exclude>
? ? ? ? ? ? ? ? <groupId>org.projectlombok</groupId>
? ? ? ? ? ? ? ? <artifactId>lombok</artifactId>
? ? ? ? ? ? </exclude>
? ? ? ? </excludes>
? ? </configuration>
? ? <executions>
? ? ? ? <execution>
? ? ? ? ? ? <id>repackage</id>
? ? ? ? ? ? <goals>
? ? ? ? ? ? ? ? <goal>repackage</goal>
? ? ? ? ? ? </goals>
? ? ? ? </execution>
? ? </executions>
</plugin>


使用maven執(zhí)行 clean and package ,將在target\classes下生成 git.json文件,內(nèi)容如下:


#Generated by Git-Commit-Id-Plugin
git.build.time=2024-02-21T10\:41\:24+0800
git.build.version=0.0.1-SNAPSHOT
git.commit.id.abbrev=3fc9c80
git.commit.id.full=3fc9c8009a48e22ef171c98a97398005e9f30a4a

同時(shí),如果我們反編譯生成的jar包,將在BOOT-INF/classes下看到git.json 文件

GitCommitIdMavenPlugin插件有豐富的配置選項(xiàng),更多配置參考:



<configuration>
? ? <!--
? ? ? ? ? ? ? ? ? ? git文件記錄,默認(rèn)是
? ? ? ? ? ? ? ? ? ? ${project.basedir}/.git
? ? ? ? ? ? ? ? ? ? 如果非默認(rèn),可以指定,例如: ${project.basedir}/../.git
? ? ? ? ? ? ? ? -->
? ? <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
? ? <!--
? ? ? ? ? ? ? ? ? ? 屬性前綴,可以理解為namespace,默認(rèn)是git, 例如 `${configured-prefix}.commit.id`.
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? 更多信息可以參考 (see
? ? ? ? ? ? ? ? ? ? https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/137#issuecomment-418144756
? ? ? ? ? ? ? ? ? ? for a full example).
? ? ? ? ? ? ? ? -->
? ? <prefix>git</prefix>
? ? <!-- @since 2.2.0 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)的日期格式,使用方式(e.g. `git.commit.time` and `git.build.time`).
? ? ? ? ? ? ? ? ?-->
? ? <dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
? ? <!-- @since 2.2.0 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 時(shí)區(qū)(java.util.TimeZone.getDefault().getID()).
? ? ? ? ? ? ? ? ? ? *Note*: 指定時(shí)區(qū)可以如下 `MAVEN_OPTS=-Duser.timezone=UTC mvn clean package`, `mvn clean package -Duser.timezone=UTC`
? ? ? ? ? ? ? ? ? ?或者使用 Asia/Shanghai 直接指定,該屬性會(huì)使用在
? ? ? ? ? ? ? ? ? ? (e.g. `git.commit.time` and `git.build.time`).
? ? ? ? ? ? ? ? -->
? ? <dateFormatTimeZone>${user.timezone}</dateFormatTimeZone>
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)false,構(gòu)建時(shí)打印信息
? ? ? ? ? ? ? ? -->
? ? <verbose>false</verbose>
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)false, 如果是true, 會(huì)生成properties 文件(填充文件中的屬性值),文件配置在 generateGitPropertiesFilename 中, 構(gòu)建時(shí)間使用如下
? ? ? ? ? ? ? ? ? ? ``` git.build.time=${git.build.time}
? ? ? ? ? ? ? ? ? ? ```
? ? ? ? ? ? ? ? -->
? ? <generateGitPropertiesFile>true</generateGitPropertiesFile>
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)文件
? ? ? ? ? ? ? ? ? ? ${project.build.outputDirectory}/git.properties
? ? ? ? ? ? ? ? ? ? 該路徑可以使用相對(duì)于${project.basedir}的相對(duì)路徑(e.g. target/classes/git.properties),或者全路徑(e.g. ${project.build.outputDirectory}/git.properties)
? ? ? ? ? ? ? ? -->
? ? <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
? ? <!--
? ? ? ? ? ? ? ? ? ?文件格式,默認(rèn)properties,可以使用json
如果將其設(shè)置為“json”,則還應(yīng)該簽出關(guān)于 `commitIdGenerationMode` 而且設(shè)置
? ? ? ? ? ? ? ? ? ? `<commitIdGenerationMode>full</commitIdGenerationMode>`.
? ? ? ? ? ? ? ? -->
? ? <format>properties</format>
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)是true,如果打包是pom(e.g. `<packaging>pom</packaging>`),則運(yùn)行該插件
? ? ? ? ? ? ? ? -->
? ? <skipPoms>true</skipPoms>
? ? <!-- @since 2.1.4 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 告訴maven git commit id將git屬性注入到所有reactor項(xiàng)目中,而不僅僅是現(xiàn)在的那個(gè)。默認(rèn)情況下,屬性設(shè)置為“false”,以防止重寫(xiě)可能與項(xiàng)目無(wú)關(guān)的屬性。如果需要公開(kāi)git屬性對(duì)于另一個(gè)maven模塊(例如maven antrun plugin),您需要將其設(shè)置為“true”。
? ? ? ? ? ? ? ? -->
? ? <injectAllReactorProjects>false</injectAllReactorProjects>
? ? <!-- @since 2.0.4 -->
? ? <!-- 默認(rèn)false, 指定在找不到.git目錄時(shí)插件是否應(yīng)失敗。當(dāng)設(shè)置為“false”并且沒(méi)有找到.git目錄時(shí),插件將跳過(guò)執(zhí)行。
? ? ? ? ? ? ? ? -->
? ? <failOnNoGitDirectory>true</failOnNoGitDirectory>
? ? <!-- @since 2.1.5 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)true,默認(rèn)情況下,如果插件無(wú)法獲取足夠的數(shù)據(jù)來(lái)完成,跳過(guò)執(zhí)行該插件。
? ? ? ? ? ? ? ? -->
? ? <failOnUnableToExtractRepoInfo>true</failOnUnableToExtractRepoInfo>
? ? <!-- @since 2.1.8 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)false, 當(dāng)設(shè)置為“true”時(shí),插件執(zhí)行將完全跳過(guò)。這對(duì)于配置文件激活的插件調(diào)用或使用屬性來(lái)啟用/禁用pom功能。在版本*2.2.3*中,您還可以使用命令行選項(xiàng)跳過(guò)插件`-Dmaven.gitcommitid.skip=true`
? ? ? ? ? ? ? ? -->
? ? <skip>false</skip>
? ? <!-- @since 3.0.1 -->
? ? <!--
? ? ? ? ? ? ? ? ? ?默認(rèn)false,當(dāng)設(shè)置為“true”時(shí),插件將不會(huì)嘗試聯(lián)系任何遠(yuǎn)程存儲(chǔ)庫(kù)。任何操作都將只使用回購(gòu)的本地狀態(tài)。如果設(shè)置為“false”,它將執(zhí)行“git fetch”操作,例如確定“ahead”和“behind”分支信息。
? ? ? ? ? ? ? ? -->
? ? <offline>false</offline>
? ? <!-- @since 2.1.12 -->
? ? <!--
默認(rèn) false,如果為true,只在一個(gè)模塊中運(yùn)行一次。這意味著插件的效果對(duì)執(zhí)行圖中的第一個(gè)項(xiàng)目執(zhí)行一次
? ? ? ? ? ? ? ? -->
? ? <runOnlyOnce>false</runOnlyOnce>
? ? <!-- @since 2.1.9 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 排除屬性 ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? -->
? ? <excludeProperties>
? ? ? ? <!-- <excludeProperty>git.user.*</excludeProperty> -->
? ? </excludeProperties>
? ? <!-- @since 2.1.14 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 只包含某類屬性,和excludeProperties相對(duì)
? ? ? ? ? ? ? ? -->
? ? <includeOnlyProperties>
? ? ? ? <!-- <includeOnlyProperty>^git.commit.id.full$</includeOnlyProperty> -->
? ? </includeOnlyProperties>
? ? <!-- @since 2.2.3 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 屬性替換,匹配到規(guī)則的屬性值在某個(gè)階段替換為另外的屬性值
? ? ? ? ? ? ? ? -->
? ? <replacementProperties>
? ? ? ? <!--
? ? ? ? ? ? ? ? ? ? ? example:
? ? ? ? ? ? ? ? ? ? ? apply replacement only to the specific property git.branch and replace '/' with '-'
? ? ? ? ? ? ? ? ? ? ? see also [issue 138](https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/138)
? ? ? ? ? ? ? ? ? <replacementProperty>
? ? ? ? ? ? ? ? ? ? <property>git.branch</property>
? ? ? ? ? ? ? ? ? ? <propertyOutputSuffix>something</propertyOutputSuffix>
? ? ? ? ? ? ? ? ? ? <token>^([^\/]*)\/([^\/]*)$</token>
? ? ? ? ? ? ? ? ? ? <value>$1-$2</value>
? ? ? ? ? ? ? ? ? ? <regex>true</regex>
? ? ? ? ? ? ? ? ? ? <forceValueEvaluation>false</forceValueEvaluation>
? ? ? ? ? ? ? ? ? ? <transformationRules>
? ? ? ? ? ? ? ? ? ? ? <transformationRule>
? ? ? ? ? ? ? ? ? ? ? ? <apply>BEFORE</apply>
? ? ? ? ? ? ? ? ? ? ? ? <action>UPPER_CASE</action>
? ? ? ? ? ? ? ? ? ? ? </transformationRule>
? ? ? ? ? ? ? ? ? ? ? <transformationRule>
? ? ? ? ? ? ? ? ? ? ? ? <apply>AFTER</apply>
? ? ? ? ? ? ? ? ? ? ? ? <action>LOWER_CASE</action>
? ? ? ? ? ? ? ? ? ? ? </transformationRule>
? ? ? ? ? ? ? ? ? ? </transformationRules>
? ? ? ? ? ? ? ? ? </replacementProperty>
? ? ? ? ? ? ? ? ? -->
? ? </replacementProperties>
? ? <!-- @since 2.1.10 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)false,此插件附帶自定義的“jgit”實(shí)現(xiàn),用于獲取所有相關(guān)信息。如果設(shè)置為“true”,則此插件將使用本機(jī)“git”二進(jìn)制文件而不是自定義的“jgit”, 也可以使用以下命令開(kāi)啟 `-Dmaven.gitcommitid.nativegit=true`
? ? ? ? ? ? ? ? -->
? ? <useNativeGit>false</useNativeGit>
? ? <!-- @since 3.0.0 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)情況下,此超時(shí)設(shè)置為30000(30秒),允許指定使用本機(jī)獲取信息的超時(shí)(毫秒)
? ? ? ? ? ? ? ? -->
? ? <nativeGitTimeoutInMs>30000</nativeGitTimeoutInMs>
? ? <!-- @since v2.0.4 -->
? ? <!--
默認(rèn)7,配置縮寫(xiě)git提交id的長(zhǎng)度(`git.commit.id.abbrev`)到長(zhǎng)度至少為N。`0'具有特殊含義(簽出git/git文檔描述-描述.md)對(duì)于特殊情況,縮寫(xiě)為0)。最大值為“40”,因?yàn)樽畲骃HA-1長(zhǎng)度。
? ? ? ? ? ? ? ? ?-->
? ? <abbrevLength>7</abbrevLength>
? ? <!-- @since v2.2.0 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 目前,交換機(jī)允許兩種不同的選擇:1默認(rèn)情況下,此屬性設(shè)置為“flat”,并將生成以前已知的財(cái)產(chǎn)`git.commit.id`就像以前版本的插件一樣。保持默認(rèn)情況下,它將“flat”保留向后兼容性,不需要進(jìn)一步的操作最終用戶調(diào)整。2如果將此開(kāi)關(guān)設(shè)置為“full”,則插件將導(dǎo)出以前已知的屬性`git.commit.id`作為`git.commit.id.full`因此將生成完全有效的導(dǎo)出機(jī)制中的json對(duì)象。
? ? ? ? ? ? ? ? -->
? ? <commitIdGenerationMode>flat</commitIdGenerationMode>
? ? <!-- @since 2.1.0 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 可以用作非常強(qiáng)大的版本控制助手, 可以參考https://git-scm.com/docs/git-describe
? ? ? ? ? ? ? ? -->
? ? <gitDescribe>
? ? ? ? <!--
? ? ? ? ? ? ? ? ? ? ? ? 默認(rèn)false, 如果true,則不使用該配置
? ? ? ? ? ? ? ? ? ? -->
? ? ? ? <skip>false</skip>
? ? ? ? <!--
? ? ? ? ? ? ? ? ? ? ? ?默認(rèn)true,
在某些情況下,在提交附近找不到標(biāo)記(例如,通常在執(zhí)行淺克隆)。如果將其設(shè)置為“true”,并且未找到標(biāo)記,則此屬性將改為回退到提交的id(當(dāng)“true”時(shí),此屬性不會(huì)變?yōu)榭眨?? ? ? ? ? ? ? ? ? ? -->
? ? ? ? <always>true</always>
? ? ? ? <!--
? ? ? ? ? ? ? ? ? ? ? ? 在describe輸出中,哈希的對(duì)象id總是縮寫(xiě)為N個(gè)字母(默認(rèn)為7)
? ? ? ? ? ? ? ? ? ? -->
? ? ? ? <abbrev>7</abbrev>
? ? ? ? <!--
? ? ? ? ? ? ? ? ? ? ? ? Default (optional):
? ? ? ? ? ? ? ? ? ? ? ? -dirty
? ? ? ? ? ? ? ? ? ? ? ? 在處于“臟狀態(tài)”(未提交)的存儲(chǔ)庫(kù)上運(yùn)行“描述”時(shí)更改),說(shuō)明輸出將包含一個(gè)附加后綴
? ? ? ? ? ? ? ? ? ? -->
? ? ? ? <dirty>-dirty</dirty>
? ? ? ? <!--
? ? ? ? ? ? ? ? ? ? ? ? 默認(rèn):*,包含所有信息,
Git describe可能包含標(biāo)記名的信息。將此配置設(shè)置為僅考慮與給定模式匹配的標(biāo)記。這可以用來(lái)避免從存儲(chǔ)庫(kù)泄漏私有標(biāo)記。
? ? ? ? ? ? ? ? ? ? -->
? ? ? ? <match>*</match>
? ? ? ? <!--
默認(rèn)false,運(yùn)行g(shù)it describe時(shí),默認(rèn)情況下只查找*帶注釋的標(biāo)記*。如果您希望在描述中也考慮*輕量級(jí)標(biāo)記*,則需要把這個(gè)轉(zhuǎn)換成'true'。
? ? ? ? ? ? ? ? ? ? ? ? depth here: https://github.com/git-commit-id/git-commit-id-maven-plugin/#git-describe-and-a-small-gotcha-with-tags
? ? ? ? ? ? ? ? ? ? -->
? ? ? ? <tags>false</tags>
? ? ? ? <!--
默認(rèn)情況下,如果當(dāng)前提交被標(biāo)記,git descripe只返回標(biāo)記名。將此選項(xiàng)設(shè)置為“true”以強(qiáng)制它使用典型的describe格式化輸出格式(“${tag name}-${committes_from_tag}-g${commit_id-maybe_dirty}”),即使是“on”標(biāo)記
? ? ? ? ? ? ? ? ? ? -->
? ? ? ? <forceLongFormat>false</forceLongFormat>
? ? </gitDescribe>
? ? <!-- @since 2.2.2 -->
? ? <!--
附加的驗(yàn)證實(shí)用程序,可用于驗(yàn)證項(xiàng)目屬性是否設(shè)置
? ? ? ? ? ? ? ? -->
? ? <validationProperties>
? ? ? ? <validationProperty>
? ? ? ? ? ? <!--
用于識(shí)別驗(yàn)證的描述性名稱,不匹配(將顯示在錯(cuò)誤消息中)
? ? ? ? ? ? ? ? ? ? ? ? -->
? ? ? ? ? ? <name>validating project version</name>
? ? ? ? ? ? <!--
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?需要驗(yàn)證的值*注意*:為了能夠驗(yàn)證在pom本身您可能需要設(shè)置配置`<injectAllReactorProjects>true</injectAllReactorProjects>`。
? ? ? ? ? ? ? ? ? ? ? ? -->
? ? ? ? ? ? <value>${project.version}</value>
? ? ? ? ? ? <!--
? ? ? ? ? ? ? ? ? ? ? ? ? ? the expected value
? ? ? ? ? ? ? ? ? ? ? ? -->
? ? ? ? ? ? <shouldMatchTo><![CDATA[^.*(?<!-SNAPSHOT)$]]></shouldMatchTo>
? ? ? ? </validationProperty>
? ? ? ? <!-- the next validationProperty you would like to validate -->
? ? </validationProperties>
? ? <!-- @since 2.2.2 -->
? ? <!--
? ? ? ? ? ? ? ? ? ? 默認(rèn)true,如果有與預(yù)期不符,則校驗(yàn)失敗
? ? ? ? ? ? ? ? -->
? ? <validationShouldFailIfNoMatch>true</validationShouldFailIfNoMatch>
? ? <!-- @since 2.2.4 -->
? ? <!--默認(rèn)值(可選):默認(rèn)情況下,此屬性只需設(shè)置為“HEAD”,它應(yīng)該引用最新的在存儲(chǔ)庫(kù)中提交。
說(shuō)明:
允許告訴插件應(yīng)該使用什么提交作為生成屬性來(lái)自。
一般情況下,可以將此屬性設(shè)置為“HEAD^1”或指向分支或標(biāo)記名稱。為了支持任何類型或用例,也可以設(shè)置此配置整個(gè)提交哈?;蛩目s寫(xiě)版本。
? ? ? ? ? ? ? ? -->
? ? <evaluateOnCommit>HEAD</evaluateOnCommit>
? ? <!-- @since 3.0.0 -->
? ? <!--
默認(rèn)true,當(dāng)設(shè)置為“true”時(shí),此插件將嘗試使用生成環(huán)境中的分支名稱。
? ? ? ? ? ? ? ? -->
? ? ? ? ? ?useBranchNameFromBuildEnvironment>true</useBranchNameFromBuildEnvironment>

<!-- @since 3.0.0 -->
<!--
默認(rèn)true,說(shuō)明:
當(dāng)設(shè)置為“true”時(shí),此插件將嘗試將生成的屬性公開(kāi)到`System.getProperties()`. 設(shè)置為{@code'false'}以避免此曝光。 -->
<injectIntoSysProperties>true</injectIntoSysProperties>
</configuration>



查詢gitCommitInfo

通過(guò)編寫(xiě)一個(gè)接口,用來(lái)查詢生成的GitCommitInfo,核心代碼如下:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-832983.html


import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.*;

@Slf4j
@RestController
@RequestMapping("/version")
public class VersionController {

? ? /**
? ? ?* 獲取 git.json 中的內(nèi)容
? ? ?* @return
? ? ?* @throws IOException
? ? ?*/
? ? @GetMapping("/gitCommitId")
? ? public String getGitCommitId() throws IOException {
? ? ? ? //git.json ?or ?git.properties
? ? ? ? File file = ResourceUtils.getFile("classpath:git.json");
? ? ? ? if (file.exists()) {
? ? ? ? ? ? String s = "";
? ? ? ? ? ? InputStreamReader in = new InputStreamReader(new FileInputStream(file), "UTF-8");
? ? ? ? ? ? BufferedReader br = new BufferedReader(in);
? ? ? ? ? ? StringBuffer content = new StringBuffer();
? ? ? ? ? ? while ((s = br.readLine()) != null) {
? ? ? ? ? ? ? ? content = content.append(s);
? ? ? ? ? ? }
? ? ? ? ? ? return content.toString();
? ? ? ? } else {
? ? ? ? ? ? return "";
? ? ? ? }
? ? }
}

 

兼容性

與java的兼容性

  • java8:插件版本=4.x
  • java11:插件版本>=5

與maven的兼容性

  • maven3:插件版本=4.x
  • maven3.2.x:插件版本>=7

引用

  • https://search.maven.org/artifact/io.github.git-commit-id/git-commit-id-maven-plugin
  • https://github.com/git-commit-id/git-commit-id-maven-plugin

到了這里,關(guān)于SpringBoot使用git-commit-id-maven-plugin打包的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • git:使用git rebase合并多次commit為一個(gè)

    git:使用git rebase合并多次commit為一個(gè)

    git log:找到需要合并的最早 commit 的父級(jí) git rebase -i 73a5cd8597 除第一個(gè) pick 外,將其它改成 s,改完后保存退出 保存完后彈出 commit message 合并提示,根據(jù)這次合并的目的,重寫(xiě)commit message,改完后保存 修改為: 做完上述操作后,自動(dòng)合并多個(gè) commit 合并成為一個(gè)并提交,并生

    2024年01月25日
    瀏覽(24)
  • 使用 git rebase 合并多個(gè) commit

    首先我們查看一下當(dāng)前提交歷史: 我們通過(guò) git rebase -i 61e7d87 將 44f23cb 、 9d2725f 和 da3ba01 這三個(gè)提交合并,這里的 61e7d87 為 待合并的提交區(qū)間的前一個(gè)提交的哈希值 。 執(zhí)行之后會(huì)進(jìn)入到 vim 編輯器中,每一行代表一個(gè) todo 項(xiàng)。我們這里需要 pick 第一個(gè)提交并將后面兩個(gè)提交

    2024年01月25日
    瀏覽(25)
  • 【git使用】之修改歷史commit信息

    直接使用amend進(jìn)行修改 1.1修改commit注釋信息 1.2 修改作者、郵箱 例如:git commit --amend --author=“silinchen silinccc@gmail.com 修改完成后可用git log查看是或否修改成功 2.1 使用git log查看提交記錄 查看需要修改的內(nèi)容是哪些 2.2 rebase需要修改的commit 執(zhí)行 rebase 命令后,會(huì)出現(xiàn) reabse 的編

    2024年02月02日
    瀏覽(22)
  • 使用git rebase合并多次commit

    使用git rebase合并多次commit

    可以對(duì)某一段線性提交歷史進(jìn)行編輯、刪除、復(fù)制、粘貼;因此,合理使用rebase命令可以使我們的提交歷史干凈、簡(jiǎn)潔! 但是需要注意的是: 不要通過(guò)rebase對(duì)任何已經(jīng)提交到公共倉(cāng)庫(kù)中的commit進(jìn)行修改(你自己一個(gè)人玩的分支除外) 基本格式如下 其中-i的意思是–interacti

    2024年02月09日
    瀏覽(32)
  • 統(tǒng)一git使用方法,git狀態(tài)變遷圖,git commit提交規(guī)范

    目錄 說(shuō)明 統(tǒng)一git使用方法 git狀態(tài)變遷圖 git commit 提交規(guī)范 多次工作中多名員工不懂git多次技術(shù)分享,自行查資料學(xué)習(xí)git并使用,會(huì)出現(xiàn)使用各種偏僻的命令,異常問(wèn)題無(wú)法解決;或出現(xiàn)帶url的git合并提交;接觸git1年一直在請(qǐng)教求助一直未入門(mén)。主要是學(xué)的不對(duì),培訓(xùn)的不

    2024年02月11日
    瀏覽(24)
  • git bash可以正常commit,但是 VSCode 里不能正常commit使用的解決方法

    git bash可以正常commit,但是 VSCode 里不能正常commit使用的解決方法

    ????????同一路徑下的源碼,使用 git bash可以正常commit ,但是 使用vscode提交commit就會(huì)一直卡住,轉(zhuǎn)圈圈 。 參考方案鏈接:VS CODE GIT 500 問(wèn)題處理-pudn.com???????? ????????根據(jù)這位博主的描述,應(yīng)當(dāng)是設(shè)置的這里選擇的默認(rèn)選項(xiàng)影響了commit,當(dāng)我們?cè)赾ommit卻不添加任

    2024年02月11日
    瀏覽(26)
  • IDEA中使用git如何撤回commit的代碼

    IDEA中使用git如何撤回commit的代碼

    在開(kāi)發(fā)過(guò)程中,有時(shí)候提交代碼會(huì)發(fā)現(xiàn)提交的代碼中有不應(yīng)該提交的部分,比如說(shuō)有時(shí)候不需要我們提交本地的配置文件,這個(gè)時(shí)候就需要我們撤銷已提交的內(nèi)容重新提交 這個(gè)命令會(huì)創(chuàng)建一個(gè)新的 commit,將指定的 commit 撤銷掉。新的 commit 會(huì)保留先前提交的歷史記錄,并且會(huì)根據(jù)

    2024年02月11日
    瀏覽(65)
  • idea使用git無(wú)法commit問(wèn)題解決方案

    idea使用git無(wú)法commit問(wèn)題解決方案

    git可以方便大家管理代碼和資料。將其集成到idea中,可以方便管理代碼,實(shí)現(xiàn)版本管理和異地代碼備份。 問(wèn)題 但實(shí)際使用過(guò)程中,經(jīng)常由于操作錯(cuò)誤實(shí)現(xiàn)idea代碼更新變動(dòng)了,無(wú)法直接使用commit提交問(wèn)題。整理發(fā)現(xiàn)出現(xiàn)該問(wèn)題的主要原因是git創(chuàng)建倉(cāng)庫(kù)時(shí),文件夾位置選擇錯(cuò)誤

    2024年04月28日
    瀏覽(20)
  • 在git使用時(shí)不小心commit了大文件,如何刪除commit中的大文件記錄

    問(wèn)題背景:由于許多人在使用git命令的時(shí)候,習(xí)慣于使用 git add . 添加所有更改的命令,這個(gè)習(xí)慣會(huì)導(dǎo)致在進(jìn)行g(shù)it 進(jìn)行push的時(shí)候,由于無(wú)意間提交commit緩存的大文件,阻止正常的push 從而很難解決,本文為了解決這問(wèn)題,有以下小經(jīng)驗(yàn)(文章廣泛參考了其他帖子) 如果你也因

    2024年02月16日
    瀏覽(23)
  • 使用pre commit鉤子再git commit時(shí)報(bào)錯(cuò)“husky - pre-commit hook exited with code 1 (error)”

    使用pre commit鉤子再git commit時(shí)報(bào)錯(cuò)“husky - pre-commit hook exited with code 1 (error)”

    使用husky配置git commit規(guī)范 1.我們?cè)谑褂?npx husky install ,初始化之后,項(xiàng)目 根目錄 下會(huì)出現(xiàn) .husky 文件夾 2.npx husky add .husky/pre-commit \\\'npx lint-staged’命令是為了在git提交的時(shí)候,使用lint-staged格式化代碼 我們發(fā)現(xiàn)在pre-commit 文件中已經(jīng)自動(dòng)生成如下內(nèi)容: 但是兩次執(zhí)行g(shù)it commit時(shí)控制

    2024年02月11日
    瀏覽(99)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包