springboot项目自动拉取git信息的配置方法
<build> <resources> <resource> <directory>src/main/resources</directory> <targetPath>${project.build.outputDirectory}</targetPath> <includes> <include>**/**</include> </includes> <!-- 开启变量注入,resources目录下的文件可以使用这些注入的变量--> <filtering>true</filtering> </resource> </resources> <plugins> <plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> <executions> <execution> <id>get-the-git-infos</id> <phase>initialize</phase> <goals> <goal>revision</goal> </goals> </execution> </executions> <configuration> <verbose>false</verbose> <dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat> <generateGitPropertiesFile>true</generateGitPropertiesFile> <generateGitPropertiesFilename>${project.build.outputDirectory}/.gitinfo </generateGitPropertiesFilename> <format>json</format> <includeOnlyProperties> <includeOnlyProperty>^git.branch$</includeOnlyProperty> <includeOnlyProperty>^git.build.version$</includeOnlyProperty> <includeOnlyProperty>^git.commit.id.full$</includeOnlyProperty> <includeOnlyProperty>^git.commit.id.abbrev</includeOnlyProperty> <includeOnlyProperty>^git.build.time$</includeOnlyProperty> <includeOnlyProperty>^git.commit.message.full$</includeOnlyProperty> </includeOnlyProperties> <commitIdGenerationMode>full</commitIdGenerationMode> <abbrevLength>11</abbrevLength> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <id>timestamp-property</id> <goals> <goal>timestamp-property</goal> </goals> <configuration> <name>build.time</name> <pattern>yyyyMMdd</pattern> <locale>zh_CN</locale> <timeZone>GMT+8</timeZone> </configuration> </execution> </executions> </plugin> </plugins> </build>
这里开启了变量注入,这样的话可以在resources目录下创建一个version文件,通过变量获取值,如:
V@project.version@_@build.time@_@git.commit.id.abbrev@