maven打包时候修改包名称带上git版本号和打包时间方式
作者:请叫我大师兄_ 发布时间:2022-03-09 20:51:39
标签:maven,打包,git版本号,打包时间
maven打包时候修改包名称带上git版本号和打包时间
使用 maven 插件 git-commit-id-plugin 可以获取项目的git信息,然后,使用这个信息,修改打包的名称,使其带上git版本号以及打包时间。
<build>
<finalName>${artifactId}-${git.commit.id.abbrev}-${git.build.time}</finalName>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.1.5</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<!-- 默认绑定阶段initialize -->
<phase>initialize</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<!--日期格式;默认值:dd.MM.yyyy '@' HH:mm:ss z;-->
<dateFormat>yyyy-MM-dd_HH-mm-ss</dateFormat>
<!--,构建过程中,是否打印详细信息;默认值:false;-->
<verbose>true</verbose>
<!-- ".git"文件路径;默认值:${project.basedir}/.git; ${project.basedir}:项目根目录,即包含pom.xml文件的目录-->
<dotGitDirectory>${project.basedir}/../../../.git</dotGitDirectory>
<!--若项目打包类型为pom,是否取消构建;默认值:true;-->
<skipPoms>false</skipPoms>
<!--是否生成"git.properties"文件;默认值:false;-->
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<!--指定"git.properties"文件的存放路径(相对于${project.basedir}的一个路径);-->
<generateGitPropertiesFilename>/src/main/resources/git.properties</generateGitPropertiesFilename>
<!--".git"文件夹未找到时,构建是否失败;若设置true,则构建失败;若设置false,则跳过执行该目标;默认值:true;-->
<failOnNoGitDirectory>true</failOnNoGitDirectory>
<!--git描述配置,可选;由JGit提供实现;-->
<gitDescribe>
<!--是否生成描述属性-->
<skip>false</skip>
<!--提交操作未发现tag时,仅打印提交操作ID,-->
<always>false</always>
<!--提交操作ID显式字符长度,最大值为:40;默认值:7; 0代表特殊意义;后面有解释;-->
<abbrev>7</abbrev>
<!--构建触发时,代码有修改时(即"dirty state"),添加指定后缀;默认值:"";-->
<dirty>-dirty</dirty>
<!--always print using the "tag-commits_from_tag-g_commit_id-maybe_dirty" format, even if "on" a tag.
The distance will always be 0 if you're "on" the tag. -->
<forceLongFormat>false</forceLongFormat>
</gitDescribe>
</configuration>
</plugin>
</plugins>
</build>
实际运行结果:
git.properties文件内容
#Generated by Git-Commit-Id-Plugin
#Fri Nov 12 15:06:14 CST 2021
git.commit.id.abbrev=ff60f80
git.commit.user.email=xxx@163.com
git.commit.message.full=git提交说明
git.commit.id=ff60f8091627e53891fc15bdccad93115f8623c9
git.commit.message.short=简要说明
git.commit.user.name=abc
git.build.user.name=efg
git.commit.id.describe=xxxx
git.build.user.email=xxx@163.com
git.branch=xxx-dev
git.commit.time=2011-11-09_14-00-40
git.build.time=2011-11-12_15-06-14
git.remote.origin.url=http\://1.1.1.1\:1/group/xxx.git
maven打包日常总结
1、 将第三方依赖性jar包中的文件打包入jar中,打包时修改引入jar包的包名,防止包冲突
<!--将第三方依赖性jar包中的文件打包入jar中-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<!-- 打包失败可能是版本太低,提高版本 -->
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- 打包时修改引入jar包的包名,防止包冲突 -->
<relocations>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>shaded.org.apache.http</shadedPattern>
<!--<excludes>-->
<!--<exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>-->
<!--<exclude>org.codehaus.plexus.util.xml.pull.*</exclude>-->
<!--</excludes>-->
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
2、阻止第三方jar包被打入执行包
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.2</version>
<!-- 阻止第三方jar包被打入执行包 -->
<scope>provided</scope>
</dependency>
3、打包时不包含该包下的部分子包
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.3.2</version>
<!-- 不包含org.apache.httpcomponents包 -->
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</exclusion>
</exclusions>
</dependency>
来源:https://blog.csdn.net/qq_27093465/article/details/121288457


猜你喜欢
- 在实际的工作中直接使用反射的机会比较少,有印象的就是一次自己做的WinForms小工具的时候利用反射来动态获取窗体上的每个控件,并且为必要的
- String对象是不可变的:意思就是无论是对String的新增或修改,出现一个全新的String内容时,都意味着诞生了一个新的对象。但是如果
- 一、树1.1 概念与线性表表示的一一对应的线性关系不同,树表示的是数据元素之间更为复杂的非线性关系。直观来看,树是以分支关系定义的层次结构。
- 1、启动新Activty1.1、功能分析App功能在第一个Activity输入消息点击第一个Activity的发送按钮发送消息到第二个Act
- 本文实例讲述了C#中foreach原理以及模拟的实现方法,分享给大家供大家参考。具体如下:public class Person:IEnum
- 1 SeekBar简介SeekBar是进度条。我们使用进度条时,可以使用系统默认的进度条;也可以自定义进度条的图片和滑块图片等。2 Seek
- 一、了解Spring自动装配的方式采用传统的XML方式配置Bean组件的关键代码如下所示<bean id="userMapp
- 今天聊一个小伙伴在星球上的提问:问题不难,解决方案也有很多,因此我决定撸一篇文章和大家仔细说说这个问题。1. 配置文件位置首先小伙伴们要明白
- 使用开源框架是,可以直接复制源代码到自己的项目(本人在Android Studio中操作报R程序包不存在),也可以使用jar包,下面记录一下
- 方法一:<uses-permission android:name="android.permission.WAKE_LOC
- Java 项目中常常回遇到发送邮件Java 发送邮件有几种,今天先给大家介绍用 HtmlEmail 来发送邮件,我这里是用 Maven 来搭
- 递归出现栈溢出stackoverflow递归是个不断回调方法的过程,使方法一遍遍的压入栈中,递归次数多了,栈满了也就溢出了。默认的栈大小是1
- 一、线程的生命周期1.五种状态:新建状态、就绪状态、运行状态、阻塞状态、消亡状态2.就绪状态的线程表示有权利去获取CPU的时间片,CPU时间
- 在android应用中,多屏滑动是一种很常见的风格,没有采用viewpager的代码实现会很长,如果采用ViewPager,代码就会短很多,
- ThreadLocal类,代表一个线程局部变量,通过把数据放在ThreadLocal中,可以让每个线程创建一个该变量的副本。也可以看成是线程
- ExpandoObject:表示一个对象,该对象包含可在运行时动态添加和移除的成员。 dynamic dynEO = new Expando
- 网上文章虽多,但是这种效果少之又少,我真诚的献上以供大家参考实现原理:自定义ImageView对此控件进行相应的layout(动态布局).这
- RocketMQ 是什么Github 上关于 RocketMQ 的介绍:RcoketMQ 是一款低延迟、高可靠、可伸缩、易于使用的消息中间件
- 不知不觉这个春节也已经过完了,遗憾家里没网,没能及时给大家送上祝福,今天回到深圳,明天就要上班了,小伙伴们是不是和我一样呢?今天讲的是一个大
- 提到java里的注解,和我们平时的注释还是有很大的区别,主要是作为java特性来使用的,跟我们常见的类是同一个使用的层面。关于java注解的