maven打包生成git配置信息文件

1、maven新增插件

注意:低版本用jenkins打出来的branch有问题,后面换成高版本生效。

xml 复制代码
<!--打包jar 与git commit 关联插件-->
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>4.9.10</version>
                <executions>
                    <execution>
                        <id>get-the-git-infos</id>
                        <!-- 默认绑定阶段initialize -->
                        <phase>initialize</phase>
                        <goals>
                            <!-- 目标:revision -->
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- 检查的仓库根目录,${project.basedir}:项目根目录,即包含pom.xml文件的目录 -->
                    <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
                    <!-- false:扫描路径时不打印更多信息,默认值false,可以不配置 -->
                    <verbose>false</verbose>
                    <!-- 定义插件中所有时间格式,默认值:yyyy-MM-dd'T'HH:mm:ssZ -->
                    <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
                    <!-- git属性文件中各属性前缀,默认值git,可以不配置 -->
                    <prefix>git</prefix>
                    <!-- 生成git属性文件,默认false:不生成 -->
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <!-- 生成git属性文件路径及文件名,默认${project.build.outputDirectory}/git.properties -->
                    <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
                    <!-- 生成git属性文件格式,默认值properties -->
                    <format>json</format>
                    <!-- 配置git-describe命令 -->
                    <gitDescribe>
                        <skip>false</skip>
                        <always>false</always>
                        <dirty>-dirty</dirty>
                    </gitDescribe>
                </configuration>
            </plugin>

2、新增查询版本接口:

java 复制代码
/**
 * 版本信息接口
 */
@Api(tags = "VersionController", description = "version")
@Slf4j
@RestController
@RequestMapping("/version")
public class VersionController {


    /**
     * 读取git.properties版本信息文件
     * @return
     */
    @GetMapping("/getGitInfo")
    @NoAuthAspect
    public Object getGitInfo() {
        InputStream inputStream = null;
        try {
            ClassLoader classLoader = getClass().getClassLoader();
            inputStream = classLoader.getResourceAsStream("git.properties");
            // 读取文件内容,自定义一个方法实现即可
            String versionJson = IoUtil.read(inputStream, "utf-8");
            JSONObject jsonObject = JSON.parseObject(versionJson);
            return jsonObject;
        } catch (Exception e) {
            log.error("get git version info fail", e);
        } finally {
            IoUtil.close(inputStream);
        }
        return new JSONObject();
    }

}
相关推荐
家里有只小肥猫9 小时前
git回退某条/多条提交记录
git
何中应11 小时前
IDEA 中让 Git 忽略 .idea 目录
java·git·intellij-idea
星辰_mya11 小时前
Elasticsearch——待补充
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客12 小时前
Elasticsearch:使用 Elastic Workflows 构建自动化
大数据·数据库·人工智能·elasticsearch·搜索引擎·自动化·全文检索
Elastic 中国社区官方博客12 小时前
Elastic 9.3:与数据对话、构建自定义 AI agents、实现全自动化
大数据·人工智能·elasticsearch·搜索引擎·ai·自动化·全文检索
多多*13 小时前
2026年最新 测试开发工程师相关 Linux相关知识点
java·开发语言·javascript·算法·spring·java-ee·maven
小柯博客14 小时前
从零开始打造 OpenSTLinux 6.6 Yocto 系统 - STM32MP2(基于STM32CubeMX)(六)
c语言·git·stm32·单片机·嵌入式硬件·开源·yocto
lang2015092814 小时前
Tomcat Maven插件:部署与卸载的架构设计
java·tomcat·maven
静若繁花_jingjing14 小时前
Git分支命令
git
lang2015092815 小时前
Tomcat Maven插件全解析:开发部署一体化
java·tomcat·maven