• maven项目添加git版本信息


    使用插件

                <plugin>
                    <groupId>pl.project13.maven</groupId>
                    <artifactId>git-commit-id-plugin</artifactId>
                    <version>3.0.0</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>revision</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <verbose>true</verbose>
                        <generateGitPropertiesFile>true</generateGitPropertiesFile>
                        <injectAllReactorProjects>true</injectAllReactorProjects>
                    </configuration>
                </plugin>

    添加VersionController

    @Controller
    public class VersionController {
        private static final Logger logger = LoggerFactory.getLogger(VersionController.class);
        private static final String VERSION_FILE = "git.properties";
    
        @RequestMapping("/version")
        @ResponseBody
        public String version() {
            try (InputStream is = getClass().getClassLoader().getResourceAsStream(VERSION_FILE)) {
                return IOUtils.toString(is).replaceAll("
    ", "<br/>");
            } catch (IOException e) {
                logger.error("", e);
                return "Can Not Found File: " + VERSION_FILE;
            }
        }
    }

    项目打包时会在classes目录下生成git.properties文件,访问http://localhost:8080/appname/version.do即可查看线上运行的项目版本信息

  • 相关阅读:
    直线型一阶倒立摆5---硬件平台搭建
    PE view---重要参数--C语言实现
    A1132. Cut Integer
    A1131. Subway Map (30)
    A1130. Infix Expression
    A1129. Recommendation System
    A1128. N Queens Puzzle
    A1127. ZigZagging on a Tree
    A1126. Eulerian Path
    A1125. Chain the Ropes
  • 原文地址:https://www.cnblogs.com/yytxdy/p/13220087.html
Copyright © 2020-2023  润新知