maven打包时候修改包名称带上git版本号和打包时间方式
作者:请叫我大师兄_ 时间:2022-03-09 20:51:39
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
标签:maven,打包,git版本号,打包时间
0
投稿
猜你喜欢
Android 数据库打包随APK发布的实例代码
2022-05-12 11:31:15
Java中的 stop the world是什么呢
2022-09-11 21:32:42
C#中?、?.、??、??=运算符的用法
2022-11-10 18:11:51
Java中的内部类你了解吗
2022-12-11 08:29:10
Android应用中使用Fragment组件的一些问题及解决方案总结
2022-09-12 09:22:27
java实现简单的扫雷小游戏
2022-09-14 19:23:24
Android Bluetooth蓝牙技术使用流程详解
2022-07-07 02:41:16
Android使用addView动态添加组件的方法
2023-12-03 03:40:25
java中fork-join的原理解析
2023-12-13 08:49:16
Android中通知Notification使用实例(振动、灯光、声音)
2021-09-28 20:00:01
Android模拟器对应的电脑快捷键说明
2022-11-09 17:44:07
Mybatis批量插入index out of range错误的解决(较偏的错误)
2022-06-11 01:11:51
Unity3D绘制地形的实现方法
2022-12-01 01:06:46
Java之Spring注解开发案例详解
2022-05-23 05:33:02
Java调用.dll文件的方法
2023-11-23 21:16:22
android自定义组件实现仪表计数盘
2023-12-23 21:27:41
Java设计模式之享元模式
2022-09-23 12:16:07
安卓实现自定义圆形取色盘
2022-01-14 18:01:55
基于javaMybatis存进时间戳的问题
2023-11-29 02:55:51
Java IO流之字符流的使用详解
2023-10-18 11:28:08