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

}
相关推荐
寒山李白21 小时前
关于Java项目构建/配置工具方式(Gradle-Groovy、Gradle-Kotlin、Maven)的区别于选择
java·kotlin·gradle·maven
风禾万里1 天前
Git怎么管理软件版本(代码,模型,配置等)
git
失散131 天前
分布式专题——47 ElasticSearch搜索相关性详解
java·分布式·elasticsearch·架构
默默coding的程序猿1 天前
3.git的分支携带问题是什么?怎么解决?
java·git·python·svn·gitee·github·intellij-idea
铭毅天下1 天前
Elasticsearch 到 Easysearch 数据迁移 5 种方案选型实战总结
大数据·elasticsearch·搜索引擎·全文检索
天地人-神君1 天前
将.idea取消git托管
java·git·intellij-idea
譕痕1 天前
Idea 启动报 未找到有效的 Maven 安装问题
java·maven·intellij-idea
Elastic 中国社区官方博客1 天前
Elasticsearch 推理 API 增加了开放的可定制服务
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
Zach_yuan1 天前
版本控制器Git
linux·git
yumgpkpm1 天前
华为鲲鹏 Aarch64 环境下多 Oracle 数据库汇聚操作指南 CMP(类 Cloudera CDP 7.3)
大数据·hive·hadoop·elasticsearch·zookeeper·big data·cloudera