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();
    }

}
相关推荐
mall_090521 分钟前
Elasticsearch字段类型聚合排序指南
java·elasticsearch
MDY121932 分钟前
IDEA如何配置Git
git
CNRio1 小时前
Day 50:Git的高级技巧:使用Git的rebase交互式修改提交历史
大数据·git·elasticsearch
CNRio1 小时前
Day 52:Git的高级技巧:使用Git的bisect定位问题提交
大数据·git·elasticsearch
Tiam-20162 小时前
开发办公工具
git·编辑器·开发工具·敏捷开发
Elasticsearch2 小时前
Jina Code Embeddings:0.5B 和 1.5B 的 SOTA 代码检索
elasticsearch
Elasticsearch3 小时前
Jina Reranker v3:用于 SOTA 多语言 检索 的 0.6B 列表式 重排序器
elasticsearch
AC赳赳老秦4 小时前
基于DeepSeek与接口文档的智能测试数据生成实践
数据库·elasticsearch·信息可视化·流程图·数据库架构·powerbi·deepseek
muxin-始终如一4 小时前
Maven HTTP 仓库被阻止问题解决总结
java·http·maven
CNRio5 小时前
Day 55:Git的高级技巧:使用Git的worktree管理多个工作目录
大数据·git·elasticsearch