通过Jenkins构建发布spring boot项目时,常常有需求,需要把Svn的版本号更新到项目的版本上,通过有两种解决方案:

1. 通过shell命令对配置文件中的指定字符进行替换,

如:

配置文件

app-config:
isDev: 1
version: 10.0.dev.312

shell命令

sed -i "s/dev/$BUILD_NUMBER/g" src/main/resources/application.properties

2.使用spring boot插件在构建compile时,对版本号的指定字符进行自动替换:

application.yml

app-config:
version: 10.0.${prefix.revision}.312

POM文件添加plugin:

<!--svn版本号-->
<plugin>
<groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
<artifactId>maven-svn-revision-number-plugin</artifactId>
<version>1.7</version>
<configuration>
<verbose>true</verbose>
<entries>
<entry>
<prefix>prefix</prefix>
<depth>empty</depth>
</entry>
</entries>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.8.5</version>
</dependency>
</dependencies>
</plugin>
<!--替换配置文件变量-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>default-resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/classes</outputDirectory>
<useDefaultDelimiters>true</useDefaultDelimiters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

点击compile:

注:通常开发时,是不需要进行compile的,所以,为避免debug出错,可以添加application-dev.yml文件

app-config:
version: 10.0.dev.312

在target文件夹生成的application.yml可以看到版本号已经改为svn号了。

spring boot 发布自动生成svn版本号的更多相关文章

  1. 工具——代码中自动生成SVN版本号

    本节和大家讨论一下程序集版本最后一位使用SVN版本号的自动生成方法,这里就向大家简单介绍一下.在进行自动部署的时候,经常需要用脚本获取程序的最新版本号.现在我们定义每个程序集的版本信息的最末段表示SV ...

  2. Spring Boot Swagger2自动生成接口文档

    一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 1.问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 2 ...

  3. Spring boot 之自动生成API文档swagger2

    目前解决API的方案一般有两种 1.编写文档接口.2.利用一些现成的api系统.3.如我一般想搞点特色的就自己写个api系统:http://api.zhaobaolin.vip/ ,这个还支持多用户. ...

  4. Spring Boot 集成 Swagger 生成 RESTful API 文档

    原文链接: Spring Boot 集成 Swagger 生成 RESTful API 文档 简介 Swagger 官网是这么描述它的:The Best APIs are Built with Swa ...

  5. spring boot 系列之六:深入理解spring boot的自动配置

    我们知道,spring boot自动配置功能可以根据不同情况来决定spring配置应该用哪个,不应该用哪个,举个例子: Spring的JdbcTemplate是不是在Classpath里面?如果是,并 ...

  6. Spring Boot的自动配置

    Spring Boot的自动配置 --摘自https://www.hollischuang.com/archives/1791 随着Ruby.Groovy等动态语言的流行,相比较之下Java的开发显得 ...

  7. Spring Boot的自动配置原理及启动流程源码分析

    概述 Spring Boot 应用目前应该是 Java 中用得最多的框架了吧.其中 Spring Boot 最具特点之一就是自动配置,基于Spring Boot 的自动配置,我们可以很快集成某个模块, ...

  8. spring boot使用swagger生成api接口文档

    前言 在之前的文章中,使用mybatis-plus生成了对应的包,在此基础上,我们针对项目的api接口,添加swagger配置和注解,生成swagger接口文档 具体可以查看本站spring boot ...

  9. 初识Spring Boot框架(二)之DIY一个Spring Boot的自动配置

    在上篇博客初识Spring Boot框架中我们初步见识了SpringBoot的方便之处,很多小伙伴可能也会好奇这个Spring Boot是怎么实现自动配置的,那么今天我就带小伙伴我们自己来实现一个简单 ...

随机推荐

  1. python中的fstring的 !r,!a,!s

    首先是fstring的结构 f ' <text> { <expression> <optional !s, !r, or !a> <optional : fo ...

  2. navicat for mysql安装

    搜索一款navicat for mysql然后进行下载. 步骤阅读 2 当我们下载完成之后首先进行数据包的解压,同时可以运行navicat for mysql程序. 破解工具下载:https://pa ...

  3. C++入门经典-例7.3-析构函数的调用

    1:析构函数的名称标识符就是在类名标识符前面加“~”.例如: ~CPerson(); 2:实例代码: (1)title.h #include <string>//title是一个类,此为构 ...

  4. Cannot use unsafe construct in safe context

    https://stackoverflow.com/questions/25953887/how-to-use-unsafe-code-in-safe-contex I am not sure if ...

  5. Python将函数放入模块

    函数可以将通用的代码封装起来,便于其他程序或者方法调用.将函数存放在文件中,这个文件被称为模块.将函数存储在独立的模块中,可与其他程序员共享这些文件而不是整个程序. fun.py def say_hi ...

  6. C# 实现DataTable、DataSet与XML互相转换

    /**//// <summary> /// 把DataSet.DataTable.DataView格式转换成XML字符串.XML文件 /// </summary> public ...

  7. DP&图论 DAY 4 下午图论

    DP&图论  DAY 4  下午 后天考试不考二分图,双联通 考拓扑排序 图论 图的基本模型 边: 有向边构成有向图 无向边构成无向图 权值: 1.无权 2.点权 3.边权 4.负权(dij不 ...

  8. LC 245. Shortest Word Distance III 【lock, medium】

    Given a list of words and two words word1 and word2, return the shortest distance between these two ...

  9. yum安装epel源

    国内yum源的安装(163,阿里云,epel)   国内yum源的安装(163,阿里云,epel) ----阿里云镜像源 1.备份 mv /etc/yum.repos.d/CentOS-Base.re ...

  10. java:redis(redis安装配置,redis的伪集群配置)

    1.redis安装配置: .安装gcc : yum install gcc-c++ .使用FTP工具FileZilla上传redis安装包到linux根目录下(当前步骤可以替换为:在root目录下执行 ...